org.elasticsearch.client.Client.prepareMultiGet()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中org.elasticsearch.client.Client.prepareMultiGet()方法的一些代码示例,展示了Client.prepareMultiGet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Client.prepareMultiGet()方法的具体详情如下:
包路径:org.elasticsearch.client.Client
类名称:Client
方法名:prepareMultiGet

Client.prepareMultiGet介绍

[英]Multi get documents.
[中]多获取文档。

代码示例

代码示例来源:origin: loklak/loklak_server

public Set<String> existBulk(String indexName, String typeName, final Collection<String> ids) {
  if (ids == null || ids.size() == 0) return new HashSet<>();
  MultiGetResponse multiGetItemResponses = elasticsearchClient.prepareMultiGet()
      .add(indexName, typeName, ids)
      .get();
  Set<String> er = new HashSet<>();
  for (MultiGetItemResponse itemResponse : multiGetItemResponses) {
    GetResponse response = itemResponse.getResponse();
    if (response.isExists()) {
      er.add(response.getId());
    }
  }
  return er;
}

代码示例来源:origin: yacy/yacy_grid_mcp

public Set<String> existBulk(String indexName, String typeName, final Collection<String> ids) {
  if (ids == null || ids.size() == 0) return new HashSet<>();
  MultiGetResponse multiGetItemResponses = elasticsearchClient.prepareMultiGet()
      .add(indexName, typeName, ids)
      .get();
  Set<String> er = new HashSet<>();
  for (MultiGetItemResponse itemResponse : multiGetItemResponses) { 
    GetResponse response = itemResponse.getResponse();
    if (response.isExists()) {                      
      er.add(response.getId());
    }
  }
  return er;
}

代码示例来源:origin: ncolomer/elasticsearch-osmosis-plugin

protected <T extends ESEntity> MultiGetRequestBuilder buildMultiGetRequest(Class<T> entityClass, long... osmIds) {
  ESEntityType type = ESEntityType.valueOf(entityClass);
  MultiGetRequestBuilder request = client.prepareMultiGet();
  for (long osmId : osmIds) {
    request.add(new Item(indexName, type.getIndiceName(), String.valueOf(osmId)));
  }
  return request;
}

代码示例来源:origin: jloisel/elastic-crud

@SuppressWarnings("unchecked")
@Override
public List<T> findAll(final List<String> ids) {
 if (ids.isEmpty()) {
  return ImmutableList.of();
 }
 final Builder<T> builder = ImmutableList.builder();
 final MultiGetResponse response = client
  .prepareMultiGet()
  .add(index, type, ids)
  .execute()
  .actionGet();
 for(final MultiGetItemResponse item : response.getResponses()) {
  final GetResponse get = item.getResponse();
  if(get.isSourceEmpty()) {
   continue;
  }
  final String json = get.getSourceAsString();
  final T entity = deserializer.apply(json);
  builder.add((T) entity.withId(get.getId()));
 }
 return builder.build();
}

代码示例来源:origin: ncolomer/elasticsearch-osmosis-plugin

protected Iterator<MultiGetItemResponse> getNodeItems(List<Way> ways) {
  MultiGetRequestBuilder request = client.prepareMultiGet();
  for (Way way : ways) {
    for (WayNode wayNode : way.getWayNodes()) {
      request.add(new Item(indexName, ESEntityType.NODE.getIndiceName(),
          String.valueOf(wayNode.getNodeId())));
    }
  }
  MultiGetResponse responses = request.execute().actionGet();
  Iterator<MultiGetItemResponse> iterator = responses.iterator();
  return iterator;
}

代码示例来源:origin: alien4cloud/alien4cloud

/** Bulk id request API. */
  @ApiOperation(value = "Get a list of environment from their ids.", authorizations = { @Authorization("ADMIN") })
  @RequestMapping(value = "/bulk/ids", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
  @PreAuthorize("hasAuthority('ADMIN')")
  public JsonRawRestResponse getByIds(@RequestBody String[] deploymentIds) {
    // Check topology status for this deployment object
    MultiGetResponse response = alienDAO.getClient().prepareMultiGet()
        .add(alienDAO.getIndexForType(ApplicationEnvironment.class), MappingBuilder.indexTypeFromClass(ApplicationEnvironment.class), deploymentIds)
        .get();
    JsonRawRestResponse restResponse = new JsonRawRestResponse();
    restResponse.setData(ResponseUtil.rawMultipleData(response));
    return restResponse;
  }
}

代码示例来源:origin: alien4cloud/alien4cloud

/**
   * Bulk id request API.
   */
  @ApiOperation(value = "Get a list of deployments from their ids.", authorizations = { @Authorization("ADMIN") })
  @RequestMapping(value = "/bulk/ids", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
  @PreAuthorize("hasAuthority('ADMIN')")
  public JsonRawRestResponse getByIds(@RequestBody String[] deploymentIds) {
    // Check topology status for this deployment object
    MultiGetResponse response = alienDAO.getClient().prepareMultiGet()
        .add(alienDAO.getIndexForType(Deployment.class), MappingBuilder.indexTypeFromClass(Deployment.class), deploymentIds).get();
    JsonRawRestResponse restResponse = new JsonRawRestResponse();
    restResponse.setData(ResponseUtil.rawMultipleData(response));
    return restResponse;
  }
}

代码示例来源:origin: alien4cloud/alien4cloud

@Override
@SneakyThrows({ IOException.class })
public <T> List<T> findByIds(Class<T> clazz, String... ids) {
  String indexName = getIndexForType(clazz);
  String typeName = MappingBuilder.indexTypeFromClass(clazz);
  MultiGetResponse response = getClient().prepareMultiGet().add(indexName, typeName, ids).execute().actionGet();
  if (response == null || response.getResponses() == null || response.getResponses().length == 0) {
    ESIndexMapper.getLog().debug("Nothing found in index [ {} ], type [ {} ], for Ids [ {} ].", indexName, typeName, Arrays.toString(ids));
    return null;
  }
  List<T> result = new ArrayList<>();
  for (MultiGetItemResponse getItemResponse : response.getResponses()) {
    if (getItemResponse.getResponse().isExists()) {
      result.add(getJsonMapper().readValue(getItemResponse.getResponse().getSourceAsString(), clazz));
    }
  }
  return result;
}

代码示例来源:origin: com.erudika/para

@Override
@SuppressWarnings("unchecked")
public <P extends ParaObject> List<P> findByIds(String appid, List<String> ids) {
  List<P> list = new LinkedList<P>();
  if (ids == null || ids.isEmpty()) {
    return list;
  }
  try {
    MultiGetRequestBuilder mgr = client().prepareMultiGet();
    for (String id : ids) {
      MultiGetRequest.Item i = new MultiGetRequest.Item(getIndexName(appid), null, id);
      mgr.add(i);
    }
    MultiGetResponse response = mgr.execute().actionGet();
    for (MultiGetItemResponse multiGetItemResponse : response.getResponses()) {
      GetResponse res = multiGetItemResponse.getResponse();
      if (res.isExists() && !res.isSourceEmpty()) {
        list.add((P) Utils.setAnnotatedFields(res.getSource()));
      }
    }
  } catch (Exception e) {
    logger.warn(null, e);
  }
  return list;
}

相关文章