Search in sources :

Example 11 with MultiGetResponse

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;
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) ArrayList(java.util.ArrayList) SneakyThrows(lombok.SneakyThrows)

Example 12 with MultiGetResponse

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;
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) JsonRawRestResponse(alien4cloud.rest.model.JsonRawRestResponse) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with MultiGetResponse

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;
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) JsonRawRestResponse(alien4cloud.rest.model.JsonRawRestResponse) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with MultiGetResponse

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);
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder)

Example 15 with 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);
        }
    });
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) F(play.libs.F) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)30 MultiGetItemResponse (org.elasticsearch.action.get.MultiGetItemResponse)15 MultiGetRequestBuilder (org.elasticsearch.action.get.MultiGetRequestBuilder)13 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)9 ElasticSearchClient (org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)8 DurationPoint (org.apache.skywalking.apm.collector.storage.utils.DurationPoint)8 Alias (org.elasticsearch.action.admin.indices.alias.Alias)7 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)4 HashMap (java.util.HashMap)3 GetResponse (org.elasticsearch.action.get.GetResponse)3 JsonRawRestResponse (alien4cloud.rest.model.JsonRawRestResponse)2 ApiOperation (io.swagger.annotations.ApiOperation)2 List (java.util.List)2 Map (java.util.Map)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 Item (org.elasticsearch.action.get.MultiGetRequest.Item)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2