use of org.elasticsearch.action.get.MultiGetResponse in project alien4cloud by alien4cloud.
the class ESGenericIdDAO method findByIds.
@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;
}
use of org.elasticsearch.action.get.MultiGetResponse in project alien4cloud by alien4cloud.
the class DeploymentController method getByIds.
/**
* 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;
}
use of org.elasticsearch.action.get.MultiGetResponse in project alien4cloud by alien4cloud.
the class EnvironmentBulkController method getByIds.
/**
* 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;
}
use of org.elasticsearch.action.get.MultiGetResponse in project play2-elasticsearch by cleverage.
the class IndexService method multiGet.
/**
* Get Indexable Object for an Id
*
* @param indexPath
* @param clazz
* @return
*/
public static <T extends Index> List<T> multiGet(IndexQueryPath indexPath, Class<T> clazz, Collection<String> ids) {
MultiGetRequestBuilder multiGetRequestBuilder = getMultiGetRequestBuilder(indexPath, ids);
MultiGetResponse multiGetResponse = multiGetRequestBuilder.execute().actionGet();
return getTsFromMultiGetResponse(clazz, multiGetResponse);
}
use of org.elasticsearch.action.get.MultiGetResponse in project play2-elasticsearch by cleverage.
the class IndexService method multiGetAsync.
/**
* Get Indexable Object for an Ids asynchronously
* @param indexPath
* @param clazz
* @param ids
* @param List<T>
* @return
*/
public static <T extends Index> F.Promise<List<T>> multiGetAsync(IndexQueryPath indexPath, final Class<T> clazz, Collection<String> ids) {
MultiGetRequestBuilder multiGetRequestBuilder = getMultiGetRequestBuilder(indexPath, ids);
F.Promise<MultiGetResponse> responsePromise = AsyncUtils.executeAsyncJava(multiGetRequestBuilder);
return responsePromise.filter(null).map(new F.Function<MultiGetResponse, List<T>>() {
public List<T> apply(MultiGetResponse getResponse) {
return getTsFromMultiGetResponse(clazz, getResponse);
}
});
}
Aggregations