當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。