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;
}
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;
}
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);
}
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);
}
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"));
}
}
}
}
Aggregations