Search in sources :

Example 6 with MinAggregationBuilder

use of org.opensearch.search.aggregations.metrics.MinAggregationBuilder in project fess by codelibs.

the class EsAbstractConditionAggregation method regMinA.

protected MinAggregationBuilder regMinA(String name, String field) {
    MinAggregationBuilder builder = AggregationBuilders.min(name).field(field);
    regA(builder);
    return builder;
}
Also used : MinAggregationBuilder(org.opensearch.search.aggregations.metrics.MinAggregationBuilder)

Example 7 with MinAggregationBuilder

use of org.opensearch.search.aggregations.metrics.MinAggregationBuilder in project fess by codelibs.

the class EsAbstractConditionAggregation method regMinA.

protected MinAggregationBuilder regMinA(String name, String field) {
    MinAggregationBuilder builder = AggregationBuilders.min(name).field(field);
    regA(builder);
    return builder;
}
Also used : MinAggregationBuilder(org.opensearch.search.aggregations.metrics.MinAggregationBuilder)

Example 8 with MinAggregationBuilder

use of org.opensearch.search.aggregations.metrics.MinAggregationBuilder in project OpenSearch by opensearch-project.

the class ChildrenToParentAggregatorTests method testCase.

private void testCase(Query query, IndexSearcher indexSearcher, Consumer<InternalParent> verify) throws IOException {
    ParentAggregationBuilder aggregationBuilder = new ParentAggregationBuilder("_name", CHILD_TYPE);
    aggregationBuilder.subAggregation(new MinAggregationBuilder("in_parent").field("number"));
    MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
    InternalParent result = searchAndReduce(indexSearcher, query, aggregationBuilder, fieldType);
    verify.accept(result);
}
Also used : MinAggregationBuilder(org.opensearch.search.aggregations.metrics.MinAggregationBuilder) MappedFieldType(org.opensearch.index.mapper.MappedFieldType)

Example 9 with MinAggregationBuilder

use of org.opensearch.search.aggregations.metrics.MinAggregationBuilder in project OpenSearch by opensearch-project.

the class ParentToChildrenAggregatorTests method testCase.

private void testCase(Query query, IndexSearcher indexSearcher, Consumer<InternalChildren> verify) throws IOException {
    ChildrenAggregationBuilder aggregationBuilder = new ChildrenAggregationBuilder("_name", CHILD_TYPE);
    aggregationBuilder.subAggregation(new MinAggregationBuilder("in_child").field("number"));
    MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
    InternalChildren result = searchAndReduce(indexSearcher, query, aggregationBuilder, fieldType);
    verify.accept(result);
}
Also used : MinAggregationBuilder(org.opensearch.search.aggregations.metrics.MinAggregationBuilder) MappedFieldType(org.opensearch.index.mapper.MappedFieldType)

Example 10 with MinAggregationBuilder

use of org.opensearch.search.aggregations.metrics.MinAggregationBuilder in project OpenSearch by opensearch-project.

the class ParentToChildrenAggregatorTests method testParentChildAsSubAgg.

public void testParentChildAsSubAgg() throws IOException {
    try (Directory directory = newDirectory()) {
        RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
        final Map<String, Tuple<Integer, Integer>> expectedParentChildRelations = setupIndex(indexWriter);
        indexWriter.close();
        try (IndexReader indexReader = OpenSearchDirectoryReader.wrap(DirectoryReader.open(directory), new ShardId(new Index("foo", "_na_"), 1))) {
            IndexSearcher indexSearcher = newSearcher(indexReader, false, true);
            AggregationBuilder request = new TermsAggregationBuilder("t").field("kwd").subAggregation(new ChildrenAggregationBuilder("children", CHILD_TYPE).subAggregation(new MinAggregationBuilder("min").field("number")));
            long expectedEvenChildCount = 0;
            double expectedEvenMin = Double.MAX_VALUE;
            long expectedOddChildCount = 0;
            double expectedOddMin = Double.MAX_VALUE;
            for (Map.Entry<String, Tuple<Integer, Integer>> e : expectedParentChildRelations.entrySet()) {
                if (Integer.valueOf(e.getKey().substring("parent".length())) % 2 == 0) {
                    expectedEvenChildCount += e.getValue().v1();
                    expectedEvenMin = Math.min(expectedEvenMin, e.getValue().v2());
                } else {
                    expectedOddChildCount += e.getValue().v1();
                    expectedOddMin = Math.min(expectedOddMin, e.getValue().v2());
                }
            }
            StringTerms result = searchAndReduce(indexSearcher, new MatchAllDocsQuery(), request, longField("number"), keywordField("kwd"));
            StringTerms.Bucket evenBucket = result.getBucketByKey("even");
            InternalChildren evenChildren = evenBucket.getAggregations().get("children");
            InternalMin evenMin = evenChildren.getAggregations().get("min");
            assertThat(evenChildren.getDocCount(), equalTo(expectedEvenChildCount));
            assertThat(evenMin.getValue(), equalTo(expectedEvenMin));
            if (expectedOddChildCount > 0) {
                StringTerms.Bucket oddBucket = result.getBucketByKey("odd");
                InternalChildren oddChildren = oddBucket.getAggregations().get("children");
                InternalMin oddMin = oddChildren.getAggregations().get("min");
                assertThat(oddChildren.getDocCount(), equalTo(expectedOddChildCount));
                assertThat(oddMin.getValue(), equalTo(expectedOddMin));
            } else {
                assertNull(result.getBucketByKey("odd"));
            }
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) AggregationBuilder(org.opensearch.search.aggregations.AggregationBuilder) MinAggregationBuilder(org.opensearch.search.aggregations.metrics.MinAggregationBuilder) TermsAggregationBuilder(org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder) Index(org.opensearch.index.Index) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ShardId(org.opensearch.index.shard.ShardId) TermsAggregationBuilder(org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder) StringTerms(org.opensearch.search.aggregations.bucket.terms.StringTerms) InternalMin(org.opensearch.search.aggregations.metrics.InternalMin) IndexReader(org.apache.lucene.index.IndexReader) MinAggregationBuilder(org.opensearch.search.aggregations.metrics.MinAggregationBuilder) Map(java.util.Map) HashMap(java.util.HashMap) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Tuple(org.opensearch.common.collect.Tuple) Directory(org.apache.lucene.store.Directory)

Aggregations

MinAggregationBuilder (org.opensearch.search.aggregations.metrics.MinAggregationBuilder)13 IndexReader (org.apache.lucene.index.IndexReader)7 Directory (org.apache.lucene.store.Directory)7 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)7 IndexSearcher (org.apache.lucene.search.IndexSearcher)6 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)5 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)5 Document (org.apache.lucene.document.Document)4 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)4 AggregationBuilder (org.opensearch.search.aggregations.AggregationBuilder)4 InternalMin (org.opensearch.search.aggregations.metrics.InternalMin)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Field (org.apache.lucene.document.Field)2 IndexWriter (org.apache.lucene.index.IndexWriter)2 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)2 IndexableField (org.apache.lucene.index.IndexableField)2 Term (org.apache.lucene.index.Term)2