Search in sources :

Example 1 with InternalGlobal

use of org.elasticsearch.search.aggregations.bucket.global.InternalGlobal in project elasticsearch by elastic.

the class GlobalAggregatorTests method testCase.

// Note that `global`'s fancy support for ignoring the query comes from special code in AggregationPhase. We don't test that here.
private void testCase(CheckedConsumer<RandomIndexWriter, IOException> buildIndex, BiConsumer<InternalGlobal, InternalMin> verify) throws IOException {
    Directory directory = newDirectory();
    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    buildIndex.accept(indexWriter);
    indexWriter.close();
    IndexReader indexReader = DirectoryReader.open(directory);
    IndexSearcher indexSearcher = newSearcher(indexReader, true, true);
    GlobalAggregationBuilder aggregationBuilder = new GlobalAggregationBuilder("_name");
    aggregationBuilder.subAggregation(new MinAggregationBuilder("in_global").field("number"));
    MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
    fieldType.setName("number");
    try (GlobalAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType)) {
        try {
            aggregator.preCollection();
            indexSearcher.search(new MatchAllDocsQuery(), aggregator);
            aggregator.postCollection();
            InternalGlobal result = (InternalGlobal) aggregator.buildAggregation(0L);
            verify.accept(result, (InternalMin) result.getAggregations().asMap().get("in_global"));
        } finally {
            IOUtils.close(aggregator.subAggregators());
        }
    }
    indexReader.close();
    directory.close();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) InternalGlobal(org.elasticsearch.search.aggregations.bucket.global.InternalGlobal) IndexReader(org.apache.lucene.index.IndexReader) MinAggregationBuilder(org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory) GlobalAggregationBuilder(org.elasticsearch.search.aggregations.bucket.global.GlobalAggregationBuilder) GlobalAggregator(org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator)

Aggregations

IndexReader (org.apache.lucene.index.IndexReader)1 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Directory (org.apache.lucene.store.Directory)1 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)1 GlobalAggregationBuilder (org.elasticsearch.search.aggregations.bucket.global.GlobalAggregationBuilder)1 GlobalAggregator (org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator)1 InternalGlobal (org.elasticsearch.search.aggregations.bucket.global.InternalGlobal)1 MinAggregationBuilder (org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder)1