当前位置: 首页>>代码示例>>Java>>正文


Java Aggregation类代码示例

本文整理汇总了Java中org.elasticsearch.search.aggregations.Aggregation的典型用法代码示例。如果您正苦于以下问题:Java Aggregation类的具体用法?Java Aggregation怎么用?Java Aggregation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Aggregation类属于org.elasticsearch.search.aggregations包,在下文中一共展示了Aggregation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doReduce

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
@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());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:BucketMetricsPipelineAggregator.java

示例2: reduceAggregationResults

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
private static AggregationResult reduceAggregationResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
    if (aggs.size() == 0) {
        throw new MemgraphException("Cannot reduce zero sized aggregation list");
    }
    Aggregation first = aggs.get(0);
    if (first instanceof HistogramAggregation || first instanceof InternalHistogram || first instanceof InternalDateHistogram) {
        return reduceHistogramResults(query, aggs);
    }
    if (first instanceof RangeAggregation || first instanceof InternalRange) {
        return reduceRangeResults(query, aggs);
    }
    if (first instanceof PercentilesAggregation || first instanceof Percentiles) {
        return reducePercentilesResults(query, aggs);
    }
    if (first instanceof TermsAggregation || first instanceof InternalTerms) {
        return reduceTermsResults(query, aggs);
    }
    if (first instanceof GeohashAggregation || first instanceof InternalGeoHashGrid) {
        return reduceGeohashResults(query, aggs);
    }
    if (first instanceof StatisticsAggregation || first instanceof InternalExtendedStats) {
        return reduceStatisticsResults(aggs);
    }
    throw new MemgraphException("Unhandled aggregation type: " + first.getClass().getName());
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:26,代码来源:ElasticsearchGraphQueryIterable.java

示例3: reducePercentilesResults

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
private static PercentilesResult reducePercentilesResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
    List<Percentile> results = new ArrayList<>();
    if (aggs.size() != 1) {
        throw new MemgraphException("Unexpected number of aggregations. Expected 1 but found: " + aggs.size());
    }
    Aggregation agg = aggs.get(0);
    if (agg instanceof Percentiles) {
        Percentiles percentiles = (Percentiles) agg;
        StreamUtils.stream(percentiles)
                .filter(percentile -> !Double.isNaN(percentile.getValue()))
                .forEach(percentile -> results.add(new Percentile(percentile.getPercent(), percentile.getValue())));
    } else {
        throw new MemgraphException("Aggregation is not a percentile: " + agg.getClass().getName());
    }
    return new PercentilesResult(results);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:17,代码来源:ElasticsearchGraphQueryIterable.java

示例4: reduce

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
public TResult reduce(ElasticsearchSearchQueryBase query, Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey) {
    List<TBucket> buckets = new ArrayList<>();
    for (Map.Entry<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKeyEntry : bucketsByKey.entrySet()) {
        String key = bucketKeyToString(bucketsByKeyEntry.getKey());
        long count = 0;
        List<Aggregation> subAggs = new ArrayList<>();
        for (MultiBucketsAggregation.Bucket b : bucketsByKeyEntry.getValue()) {
            count += b.getDocCount();
            for (Aggregation subAgg : b.getAggregations()) {
                subAggs.add(subAgg);
            }
        }
        Map<String, AggregationResult> nestedResults = reduceAggregationResults(query, getAggregationResultsByName(query, subAggs));
        buckets.add(createBucket(key, count, nestedResults, bucketsByKeyEntry.getValue()));
    }
    return bucketsToResults(buckets);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:18,代码来源:ElasticsearchGraphQueryIterable.java

示例5: reduceStatisticsResults

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
private static StatisticsResult reduceStatisticsResults(List<Aggregation> aggs) {
    List<StatisticsResult> results = new ArrayList<>();
    for (Aggregation agg : aggs) {
        if (agg instanceof ExtendedStats) {
            ExtendedStats extendedStats = (ExtendedStats) agg;
            long count = extendedStats.getCount();
            double sum = extendedStats.getSum();
            double min = extendedStats.getMin();
            double max = extendedStats.getMax();
            double standardDeviation = extendedStats.getStdDeviation();
            results.add(new StatisticsResult(count, sum, min, max, standardDeviation));
        } else {
            throw new MemgraphException("Aggregation is not a statistics: " + agg.getClass().getName());
        }
    }
    return StatisticsResult.combine(results);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:18,代码来源:ElasticsearchGraphQueryIterable.java

示例6: doReduce

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
@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.emptyList(), metaData());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:BucketMetricsPipelineAggregator.java

示例7: testTopLevel

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
public void testTopLevel() throws Exception {
    Aggregation result;
    if (randomBoolean()) {
        result = testCase(new MatchAllDocsQuery(), topHits("_name").sort("string", SortOrder.DESC));
    } else {
        Query query = new QueryParser("string", new KeywordAnalyzer()).parse("d^1000 c^100 b^10 a^1");
        result = testCase(query, topHits("_name"));
    }
    SearchHits searchHits = ((TopHits) result).getHits();
    assertEquals(3L, searchHits.getTotalHits());
    assertEquals("3", searchHits.getAt(0).getId());
    assertEquals("type", searchHits.getAt(0).getType());
    assertEquals("2", searchHits.getAt(1).getId());
    assertEquals("type", searchHits.getAt(1).getType());
    assertEquals("1", searchHits.getAt(2).getId());
    assertEquals("type", searchHits.getAt(2).getType());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:TopHitsAggregatorTests.java

示例8: testCase

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
private Aggregation testCase(Query query, AggregationBuilder builder) throws IOException {
    Directory directory = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random(), directory);
    iw.addDocument(document("1", "a", "b"));
    iw.addDocument(document("2", "c", "a"));
    iw.addDocument(document("3", "b", "d"));
    iw.close();

    IndexReader indexReader = DirectoryReader.open(directory);
    // We do not use LuceneTestCase.newSearcher because we need a DirectoryReader for "testInsideTerms"
    IndexSearcher indexSearcher = new IndexSearcher(indexReader);

    Aggregation result = searchAndReduce(indexSearcher, query, builder, STRING_FIELD_TYPE);
    indexReader.close();
    directory.close();
    return result;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:TopHitsAggregatorTests.java

示例9: checkSignificantTermsAggregationCorrect

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
private static void checkSignificantTermsAggregationCorrect(ESIntegTestCase testCase) {
    SearchResponse response = client().prepareSearch(INDEX_NAME).setTypes(DOC_TYPE).addAggregation(
            terms("class").field(CLASS_FIELD).subAggregation(significantTerms("sig_terms").field(TEXT_FIELD)))
            .execute().actionGet();
    assertSearchResponse(response);
    StringTerms classes = response.getAggregations().get("class");
    Assert.assertThat(classes.getBuckets().size(), equalTo(2));
    for (Terms.Bucket classBucket : classes.getBuckets()) {
        Map<String, Aggregation> aggs = classBucket.getAggregations().asMap();
        Assert.assertTrue(aggs.containsKey("sig_terms"));
        SignificantTerms agg = (SignificantTerms) aggs.get("sig_terms");
        Assert.assertThat(agg.getBuckets().size(), equalTo(1));
        SignificantTerms.Bucket sigBucket = agg.iterator().next();
        String term = sigBucket.getKeyAsString();
        String classTerm = classBucket.getKeyAsString();
        Assert.assertTrue(term.equals(classTerm));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SharedSignificantTermsTestMethods.java

示例10: processFilterAgg

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
/**
 * Parse an aggregation performed without grouping.
 * @param filter
 * @param rs
 * @throws SQLException
 */
private void processFilterAgg(InternalFilter filter, ESResultSet rs) throws SQLException{
	//String name = global.getName(); // we do not care about the global name for now
	List<Object> row = rs.getNewRow();
	Column count = null;
	for(Column c : rs.getHeading().columns())
		if(c.getOp() == Operation.COUNT) count = c;
	
	if(count != null){
		row.set(count.getIndex(), filter.getDocCount());
	}
	for(Aggregation agg : filter.getAggregations()){
		if(agg instanceof InternalNumericMetricsAggregation.SingleValue){
			InternalNumericMetricsAggregation.SingleValue numericAgg = 
					(InternalNumericMetricsAggregation.SingleValue)agg;
			String name =numericAgg.getName();
			Column column = rs.getHeading().getColumnByLabel(name);
			if(column == null){
				throw new SQLException("Unable to identify column for "+name);
			}
			row.set(column.getIndex(), numericAgg.value());
		}else throw new SQLException("Unable to parse aggregation of type "+agg.getClass());
	}
	rs.add(row);
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:31,代码来源:SearchAggregationParser.java

示例11: extractTerms

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
private Set<String> extractTerms(Aggregation aggregation) {
    Set<String> terms = new HashSet<>();
    if (aggregation instanceof MultiBucketsAggregation) {
        for (MultiBucketsAggregation.Bucket bucket : ((MultiBucketsAggregation) (aggregation)).getBuckets()) {
            if (bucket.getAggregations().asList().size() != 0) {
                for (Aggregation agg : bucket.getAggregations().asList()) {
                    terms.addAll(extractTerms(agg));
                }
            } else {
                terms.add(bucket.getKeyAsString());
            }
        }
    } else {
        throw new IllegalStateException("cannot deal with non bucket aggs");
    }
    return terms;
}
 
开发者ID:brwe,项目名称:es-token-plugin,代码行数:18,代码来源:StringFieldSignificantTermsSpecRequest.java

示例12: process

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
@Override
public void process(final TransportPrepareSpecAction.FieldSpecActionListener fieldSpecActionListener, Client client) {
    client.prepareSearch(this.index).setSource(this.searchRequest).execute(new ActionListener<SearchResponse>() {
        @Override
        public void onResponse(SearchResponse searchResponse) {
            Aggregations agg = searchResponse.getAggregations();
            assert (agg.asList().size() == 1);
            Aggregation termsAgg = agg.asList().get(0);
            Set<String> terms = extractTerms(termsAgg);
            String[] finalTerms = terms.toArray(new String[terms.size()]);
            Arrays.sort(finalTerms);
            fieldSpecActionListener.onResponse(new StringFieldSpec(finalTerms, number, field));
        }

        @Override
        public void onFailure(Exception throwable) {
            fieldSpecActionListener.onFailure(throwable);
        }
    });
}
 
开发者ID:brwe,项目名称:es-token-plugin,代码行数:21,代码来源:StringFieldSignificantTermsSpecRequest.java

示例13: reduceAggregationResults

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
private static AggregationResult reduceAggregationResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
    if (aggs.size() == 0) {
        throw new VertexiumException("Cannot reduce zero sized aggregation list");
    }
    Aggregation first = aggs.get(0);
    if (first instanceof HistogramAggregation || first instanceof InternalHistogram || first instanceof InternalDateHistogram) {
        return reduceHistogramResults(query, aggs);
    }
    if (first instanceof RangeAggregation || first instanceof InternalRange) {
        return reduceRangeResults(query, aggs);
    }
    if (first instanceof PercentilesAggregation || first instanceof Percentiles) {
        return reducePercentilesResults(query, aggs);
    }
    if (first instanceof TermsAggregation || first instanceof InternalTerms) {
        return reduceTermsResults(query, aggs);
    }
    if (first instanceof GeohashAggregation || first instanceof InternalGeoHashGrid) {
        return reduceGeohashResults(query, aggs);
    }
    if (first instanceof StatisticsAggregation || first instanceof InternalExtendedStats) {
        return reduceStatisticsResults(aggs);
    }
    throw new VertexiumException("Unhandled aggregation type: " + first.getClass().getName());
}
 
开发者ID:visallo,项目名称:vertexium,代码行数:26,代码来源:ElasticsearchGraphQueryIterable.java

示例14: reducePercentilesResults

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
private static PercentilesResult reducePercentilesResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
    List<Percentile> results = new ArrayList<>();
    if (aggs.size() != 1) {
        throw new VertexiumException("Unexpected number of aggregations. Expected 1 but found: " + aggs.size());
    }
    Aggregation agg = aggs.get(0);
    if (agg instanceof Percentiles) {
        Percentiles percentiles = (Percentiles) agg;
        StreamUtils.stream(percentiles)
                .filter(percentile -> !Double.isNaN(percentile.getValue()))
                .forEach(percentile -> results.add(new Percentile(percentile.getPercent(), percentile.getValue())));
    } else {
        throw new VertexiumException("Aggregation is not a percentile: " + agg.getClass().getName());
    }
    return new PercentilesResult(results);
}
 
开发者ID:visallo,项目名称:vertexium,代码行数:17,代码来源:ElasticsearchGraphQueryIterable.java

示例15: reduceStatisticsResults

import org.elasticsearch.search.aggregations.Aggregation; //导入依赖的package包/类
private static StatisticsResult reduceStatisticsResults(List<Aggregation> aggs) {
    List<StatisticsResult> results = new ArrayList<>();
    for (Aggregation agg : aggs) {
        if (agg instanceof ExtendedStats) {
            ExtendedStats extendedStats = (ExtendedStats) agg;
            long count = extendedStats.getCount();
            double sum = extendedStats.getSum();
            double min = extendedStats.getMin();
            double max = extendedStats.getMax();
            double standardDeviation = extendedStats.getStdDeviation();
            results.add(new StatisticsResult(count, sum, min, max, standardDeviation));
        } else {
            throw new VertexiumException("Aggregation is not a statistics: " + agg.getClass().getName());
        }
    }
    return StatisticsResult.combine(results);
}
 
开发者ID:visallo,项目名称:vertexium,代码行数:18,代码来源:ElasticsearchGraphQueryIterable.java


注:本文中的org.elasticsearch.search.aggregations.Aggregation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。