Search in sources :

Example 26 with MultiGetResponse

use of org.elasticsearch.action.get.MultiGetResponse in project incubator-skywalking by apache.

the class ServiceMetricEsUIDAO method getServiceResponseTimeTrend.

@Override
public List<Integer> getServiceResponseTimeTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
    String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
    MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {

        @Override
        public void accept(DurationPoint durationPoint) {
            String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
            add(tableName, ServiceMetricTable.TABLE_TYPE, id);
        }
    });
    List<Integer> trends = new LinkedList<>();
    MultiGetResponse multiGetResponse = prepareMultiGet.get();
    for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
        if (response.getResponse().isExists()) {
            long calls = ((Number) response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
            long durationSum = ((Number) response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)).longValue();
            trends.add((int) (durationSum / calls));
        } else {
            trends.add(0);
        }
    }
    return trends;
}
Also used : MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint)

Example 27 with MultiGetResponse

use of org.elasticsearch.action.get.MultiGetResponse in project incubator-skywalking by apache.

the class ServiceMetricEsUIDAO method getServiceTPSTrend.

@Override
public List<Integer> getServiceTPSTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
    String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
    MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {

        @Override
        public void accept(DurationPoint durationPoint) {
            String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
            add(tableName, ServiceMetricTable.TABLE_TYPE, id);
        }
    });
    List<Integer> trends = new LinkedList<>();
    MultiGetResponse multiGetResponse = prepareMultiGet.get();
    int index = 0;
    for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
        if (response.getResponse().isExists()) {
            long calls = ((Number) response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
            long secondBetween = durationPoints.get(index).getSecondsBetween();
            trends.add((int) (calls / secondBetween));
        } else {
            trends.add(0);
        }
        index++;
    }
    return trends;
}
Also used : MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint)

Example 28 with MultiGetResponse

use of org.elasticsearch.action.get.MultiGetResponse in project pancm_project by xuwujing.

the class EsHighLevelRestTest2 method multiGet.

/**
 * 多查询使用
 *
 * @throws IOException
 */
private static void multiGet() throws IOException {
    MultiGetRequest request = new MultiGetRequest();
    request.add(new MultiGetRequest.Item("estest", "estest", "1"));
    request.add(new MultiGetRequest.Item("user", "userindex", "2"));
    // 禁用源检索,默认启用
    // request.add(new MultiGetRequest.Item("user", "userindex", "2").fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE));
    // 同步构建
    MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT);
    for (MultiGetItemResponse item : response.getResponses()) {
        assertNull(item.getFailure());
        GetResponse get = item.getResponse();
        String index = item.getIndex();
        String type = item.getType();
        String id = item.getId();
        // 如果请求存在
        if (get.isExists()) {
            long version = get.getVersion();
            String sourceAsString = get.getSourceAsString();
            Map<String, Object> sourceAsMap = get.getSourceAsMap();
            byte[] sourceAsBytes = get.getSourceAsBytes();
            System.out.println("查询的结果:" + sourceAsMap);
        } else {
            System.out.println("没有找到该文档!");
        }
    }
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest)

Example 29 with MultiGetResponse

use of org.elasticsearch.action.get.MultiGetResponse in project yacy_grid_mcp by yacy.

the class ElasticsearchClient method existBulk.

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

Example 30 with MultiGetResponse

use of org.elasticsearch.action.get.MultiGetResponse in project jnosql-diana-driver by eclipse.

the class EntityConverter method executeId.

private static void executeId(DocumentQuery query, RestHighLevelClient client, String index, QueryConverterResult select, List<DocumentEntity> entities) throws IOException {
    String type = query.getDocumentCollection();
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    select.getIds().stream().map(id -> new MultiGetRequest.Item(index, type, id)).forEach(multiGetRequest::add);
    MultiGetResponse responses = client.multiGet(multiGetRequest);
    Stream.of(responses.getResponses()).map(MultiGetItemResponse::getResponse).map(ElasticsearchEntry::of).filter(ElasticsearchEntry::isNotEmpty).map(ElasticsearchEntry::toEntity).forEach(entities::add);
}
Also used : Document(org.jnosql.diana.api.document.Document) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) IOException(java.io.IOException) HashMap(java.util.HashMap) MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) SearchRequest(org.elasticsearch.action.search.SearchRequest) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) StreamSupport(java.util.stream.StreamSupport) Collections.singletonMap(java.util.Collections.singletonMap) ValueUtil(org.jnosql.diana.driver.ValueUtil) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest)

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