org.elasticsearch.search.aggregations.Aggregation.getName()方法的使用及代码示例

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

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

Aggregation.getName介绍

暂无

代码示例

代码示例来源: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: NLPchina/elasticsearch-sql

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

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

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

代码示例来源: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: 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: visallo/vertexium

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;
}

代码示例来源:origin: mnemonic-no/act-platform

private Aggregation resolveChildAggregation(Aggregations aggregations, String targetAggregationName) {
 if (aggregations == null) return null;
 for (Aggregation aggregation : aggregations) {
  // Check if 'aggregation' is already the target aggregation.
  if (aggregation.getName().equals(targetAggregationName)) {
   return aggregation;
  }
  // Otherwise check all sub aggregations if applicable.
  if (HasAggregations.class.isAssignableFrom(aggregation.getClass())) {
   Aggregation target = resolveChildAggregation(HasAggregations.class.cast(aggregation).getAggregations(), targetAggregationName);
   if (target != null) return target;
  }
 }
 // Couldn't find target aggregation.
 return null;
}

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

/**
 * Reduces the given lists of addAggregation.
 *
 * @param aggregationsList  A list of aggregation to reduce
 * @return                  The reduced addAggregation
 */
public static InternalAggregations reduce(List<InternalAggregations> aggregationsList, ReduceContext context) {
  if (aggregationsList.isEmpty()) {
    return null;
  }
  // first we collect all aggregations of the same type and list them together
  Map<String, List<InternalAggregation>> aggByName = new HashMap<>();
  for (InternalAggregations aggregations : aggregationsList) {
    for (Aggregation aggregation : aggregations.aggregations) {
      List<InternalAggregation> aggs = aggByName.computeIfAbsent(
          aggregation.getName(), k -> new ArrayList<>(aggregationsList.size()));
      aggs.add((InternalAggregation)aggregation);
    }
  }
  // now we can use the first aggregation of each list to handle the reduce of its list
  List<InternalAggregation> reducedAggregations = new ArrayList<>();
  for (Map.Entry<String, List<InternalAggregation>> entry : aggByName.entrySet()) {
    List<InternalAggregation> aggregations = entry.getValue();
    InternalAggregation first = aggregations.get(0); // the list can't be empty as it's created on demand
    reducedAggregations.add(first.reduce(aggregations, context));
  }
  return new InternalAggregations(reducedAggregations);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.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: harbby/presto-connectors

@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))) {
      bucketsPath = bucketsPath.subList(1, bucketsPath.size());
      InternalMultiBucketAggregation multiBucketsAgg = (InternalMultiBucketAggregation) aggregation;
      List<? extends Bucket> buckets = multiBucketsAgg.getBuckets();
      for (int i = 0; i < buckets.size(); i++) {
        Bucket bucket = buckets.get(i);
        Double bucketValue = BucketHelpers.resolveBucketValue(multiBucketsAgg, bucket, bucketsPath, gapPolicy);
        if (bucketValue != null && !Double.isNaN(bucketValue)) {
          collectBucketValue(bucket.getKeyAsString(), bucketValue);
        }
      }
    }
  }
  return buildAggregation(Collections.EMPTY_LIST, metaData());
}

代码示例来源:origin: com.strapdata.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))) {
      bucketsPath = 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, bucketsPath, gapPolicy);
        if (bucketValue != null && !Double.isNaN(bucketValue)) {
          collectBucketValue(bucket.getKeyAsString(), bucketValue);
        }
      }
    }
  }
  return buildAggregation(Collections.emptyList(), metaData());
}

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

@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.nlpcn/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);
  }
}

相关文章