org.elasticsearch.search.aggregations.Aggregation类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(163)

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

Aggregation介绍

[英]An aggregation. Extends ToXContent as it makes it easier to print out its content.
[中]集合。扩展内容,使其更容易打印出内容。

代码示例

代码示例来源:origin: NLPchina/elasticsearch-sql

public SearchResult(SearchResponse resp, Select select) throws SqlParseException {
  Aggregations aggs = resp.getAggregations();
  if (aggs.get("filter") != null) {
    InternalFilter inf = aggs.get("filter");
    aggs = inf.getAggregations();
  }
  if (aggs.get("group by") != null) {
    InternalTerms terms = aggs.get("group by");
    Collection<Bucket> buckets = terms.getBuckets();
    this.total = buckets.size();
    results = new ArrayList<>(buckets.size());
    for (Bucket bucket : buckets) {
      Map<String, Object> aggsMap = toAggsMap(bucket.getAggregations().getAsMap());
      aggsMap.put("docCount", bucket.getDocCount());
      results.add(aggsMap);
    }
  } else {
    results = new ArrayList<>(1);
    this.total = 1;
    Map<String, Object> map = new HashMap<>();
    for (Aggregation aggregation : aggs) {
      map.put(aggregation.getName(), covenValue(aggregation));
    }
    results.add(map);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Directly write all the aggregations without their bounding object. Used by sub-aggregations (non top level aggs)
 */
public XContentBuilder toXContentInternal(XContentBuilder builder, Params params) throws IOException {
  for (Aggregation aggregation : aggregations) {
    aggregation.toXContent(builder, params);
  }
  return builder;
}

代码示例来源:origin: macrozheng/mall

List<Terms.Bucket> attrIds = ((LongTerms) ((InternalFilter)productAttrs.getProperty("productAttrs")).getAggregations().getProperty("attrIds")).getBuckets();
List<EsProductRelatedInfo.ProductAttr> attrList = new ArrayList<>();
for (Terms.Bucket attrId : attrIds) {

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

assertEquals(aggregation.getName(), agg.getName());
assertEquals(aggregation.getMetaData(), agg.getMetaData());
assertEquals(aggregation.getType(), agg.getType());

代码示例来源:origin: visallo/vertexium

TopHits exactMatchTopHits = b.getAggregations().get(ElasticsearchSearchQueryBase.TOP_HITS_AGGREGATION_NAME);
String mapKey = bucketKeyToString(b.getKey(), exactMatchTopHits);
Map<String, Object> metadata = agg.getMetaData();
if (metadata != null) {
  Object fieldName = metadata.get(ElasticsearchSearchQueryBase.AGGREGATION_METADATA_FIELD_NAME_KEY);

代码示例来源:origin: org.vertexium/vertexium-elasticsearch5

TopHits exactMatchTopHits = b.getAggregations().get(ElasticsearchSearchQueryBase.TOP_HITS_AGGREGATION_NAME);
String mapKey = bucketKeyToString(b.getKey(), exactMatchTopHits);
Map<String, Object> metadata = agg.getMetaData();
if (metadata != null) {
  Object fieldName = metadata.get(ElasticsearchSearchQueryBase.AGGREGATION_METADATA_FIELD_NAME_KEY);

代码示例来源:origin: NLPchina/elasticsearch-sql

private  void handleNumericMetricAggregation(List<String> header, List<String> line, Aggregation aggregation) throws CsvExtractorException {
  String name = aggregation.getName();

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Directly write all the aggregations without their bounding object. Used by sub-aggregations (non top level aggs)
 */
public XContentBuilder toXContentInternal(XContentBuilder builder, Params params) throws IOException {
  for (Aggregation aggregation : aggregations) {
    aggregation.toXContent(builder, params);
  }
  return builder;
}

代码示例来源:origin: NLPchina/elasticsearch-sql

private void handleNumericMetricAggregation(List<String> header, List<Object> line, Aggregation aggregation) throws ObjectResultsExtractException {
  String name = aggregation.getName();

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

/**
 * Directly write all the aggregations without their bounding object. Used by sub-aggregations (non top level aggs)
 */
public XContentBuilder toXContentInternal(XContentBuilder builder, Params params) throws IOException {
  for (Aggregation aggregation : aggregations) {
    aggregation.toXContent(builder, params);
  }
  return builder;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Returns the {@link Aggregation}s keyed by aggregation name.
 */
public final Map<String, Aggregation> getAsMap() {
  if (aggregationsAsMap == null) {
    Map<String, Aggregation> newAggregationsAsMap = new HashMap<>(aggregations.size());
    for (Aggregation aggregation : aggregations) {
      newAggregationsAsMap.put(aggregation.getName(), aggregation);
    }
    this.aggregationsAsMap = unmodifiableMap(newAggregationsAsMap);
  }
  return aggregationsAsMap;
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Directly write all the aggregations without their bounding object. Used by sub-aggregations (non top level aggs)
 */
public XContentBuilder toXContentInternal(XContentBuilder builder, Params params) throws IOException {
  for (Aggregation aggregation : aggregations) {
    aggregation.toXContent(builder, params);
  }
  return builder;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

for (Aggregation aggregation : aggregations.aggregations) {
  List<InternalAggregation> aggs = aggByName.computeIfAbsent(
      aggregation.getName(), k -> new ArrayList<>(aggregationsList.size()));
  aggs.add((InternalAggregation)aggregation);

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public final InternalAggregation doReduce(Aggregations aggregations, ReduceContext context) {
  preCollection();
  List<String> bucketsPath = AggregationPath.parse(bucketsPaths()[0]).getPathElementsAsStringList();
  for (Aggregation aggregation : aggregations) {
    if (aggregation.getName().equals(bucketsPath.get(0))) {
      List<String> sublistedPath = bucketsPath.subList(1, bucketsPath.size());
      InternalMultiBucketAggregation<?, ?> multiBucketsAgg = (InternalMultiBucketAggregation<?, ?>) aggregation;
      List<? extends InternalMultiBucketAggregation.InternalBucket> buckets = multiBucketsAgg.getBuckets();
      for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) {
        Double bucketValue = BucketHelpers.resolveBucketValue(multiBucketsAgg, bucket, sublistedPath, gapPolicy);
        if (bucketValue != null && !Double.isNaN(bucketValue)) {
          collectBucketValue(bucket.getKeyAsString(), bucketValue);
        }
      }
    }
  }
  return buildAggregation(Collections.emptyList(), metaData());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

/**
 * Returns the {@link Aggregation}s keyed by aggregation name.
 */
public final Map<String, Aggregation> getAsMap() {
  if (aggregationsAsMap == null) {
    Map<String, Aggregation> newAggregationsAsMap = new HashMap<>(aggregations.size());
    for (Aggregation aggregation : aggregations) {
      newAggregationsAsMap.put(aggregation.getName(), aggregation);
    }
    this.aggregationsAsMap = unmodifiableMap(newAggregationsAsMap);
  }
  return aggregationsAsMap;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Returns the {@link Aggregation}s keyed by aggregation name.
 */
public final Map<String, Aggregation> getAsMap() {
  if (aggregationsAsMap == null) {
    Map<String, Aggregation> newAggregationsAsMap = new HashMap<>(aggregations.size());
    for (Aggregation aggregation : aggregations) {
      newAggregationsAsMap.put(aggregation.getName(), aggregation);
    }
    this.aggregationsAsMap = unmodifiableMap(newAggregationsAsMap);
  }
  return aggregationsAsMap;
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Returns the {@link Aggregation}s keyed by aggregation name.
 */
public final Map<String, Aggregation> getAsMap() {
  if (aggregationsAsMap == null) {
    Map<String, Aggregation> newAggregationsAsMap = new HashMap<>(aggregations.size());
    for (Aggregation aggregation : aggregations) {
      newAggregationsAsMap.put(aggregation.getName(), aggregation);
    }
    this.aggregationsAsMap = unmodifiableMap(newAggregationsAsMap);
  }
  return aggregationsAsMap;
}

代码示例来源:origin: org.vertexium/vertexium-elasticsearch5

private static Map<String, List<Aggregation>> getAggregationResultsByName(ElasticsearchSearchQueryBase query, Iterable<Aggregation> aggs) {
  Map<String, List<Aggregation>> aggsByName = new HashMap<>();
  if (aggs == null) {
    return aggsByName;
  }
  for (Aggregation agg : aggs) {
    if (agg.getName().equals(ElasticsearchSearchQueryBase.TOP_HITS_AGGREGATION_NAME)) {
      continue;
    }
    String aggName = query.getAggregationName(agg.getName());
    List<Aggregation> l = aggsByName.computeIfAbsent(aggName, k -> new ArrayList<>());
    l.add(agg);
  }
  return aggsByName;
}

代码示例来源:origin: org.vertexium/vertexium-elasticsearch-singledocument

private static Map<String, List<Aggregation>> getAggregationResultsByName(ElasticSearchSingleDocumentSearchQueryBase query, Iterable<Aggregation> aggs) {
  Map<String, List<Aggregation>> aggsByName = new HashMap<>();
  if (aggs == null) {
    return aggsByName;
  }
  for (Aggregation agg : aggs) {
    String aggName = query.getAggregationName(agg.getName());
    List<Aggregation> l = aggsByName.computeIfAbsent(aggName, k -> new ArrayList<>());
    l.add(agg);
  }
  return aggsByName;
}

代码示例来源:origin: org.vertexium/vertexium-elasticsearch2

private static Map<String, List<Aggregation>> getAggregationResultsByName(ElasticsearchSearchQueryBase query, Iterable<Aggregation> aggs) {
  Map<String, List<Aggregation>> aggsByName = new HashMap<>();
  if (aggs == null) {
    return aggsByName;
  }
  for (Aggregation agg : aggs) {
    String aggName = query.getAggregationName(agg.getName());
    List<Aggregation> l = aggsByName.computeIfAbsent(aggName, k -> new ArrayList<>());
    l.add(agg);
  }
  return aggsByName;
}

相关文章