use of org.opensearch.search.aggregations.support.AggregationPath in project OpenSearch by opensearch-project.
the class InternalMultiBucketAggregationTests method testResolveToBucketCount.
public void testResolveToBucketCount() {
AggregationPath path = AggregationPath.parse("_bucket_count");
List<LongTerms.Bucket> buckets = new ArrayList<>();
InternalAggregation agg = new InternalAvg("the_avg", 2, 1, DocValueFormat.RAW, Collections.emptyMap());
InternalAggregations internalAggregations = InternalAggregations.from(Collections.singletonList(agg));
LongTerms.Bucket bucket = new LongTerms.Bucket(1, 1, internalAggregations, false, 0, DocValueFormat.RAW);
buckets.add(bucket);
Object value = resolvePropertyFromPath(path.getPathElementsAsStringList(), buckets, "the_long_terms");
assertThat(value, equalTo(1));
}
use of org.opensearch.search.aggregations.support.AggregationPath in project OpenSearch by opensearch-project.
the class InternalMultiBucketAggregationTests method testResolveToUnknown.
public void testResolveToUnknown() {
AggregationPath path = AggregationPath.parse("the_avg.unknown");
List<LongTerms.Bucket> buckets = new ArrayList<>();
InternalAggregation agg = new InternalAvg("the_avg", 2, 1, DocValueFormat.RAW, Collections.emptyMap());
InternalAggregations internalAggregations = InternalAggregations.from(Collections.singletonList(agg));
LongTerms.Bucket bucket = new LongTerms.Bucket(1, 1, internalAggregations, false, 0, DocValueFormat.RAW);
buckets.add(bucket);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> resolvePropertyFromPath(path.getPathElementsAsStringList(), buckets, "the_long_terms"));
assertThat(e.getMessage(), equalTo("path not supported for [the_avg]: [unknown]"));
}
use of org.opensearch.search.aggregations.support.AggregationPath in project OpenSearch by opensearch-project.
the class InternalMultiBucketAggregationTests method testResolveToAggValue.
public void testResolveToAggValue() {
AggregationPath path = AggregationPath.parse("the_avg.value");
List<LongTerms.Bucket> buckets = new ArrayList<>();
InternalAggregation agg = new InternalAvg("the_avg", 2, 1, DocValueFormat.RAW, Collections.emptyMap());
InternalAggregations internalAggregations = InternalAggregations.from(Collections.singletonList(agg));
LongTerms.Bucket bucket = new LongTerms.Bucket(1, 1, internalAggregations, false, 0, DocValueFormat.RAW);
buckets.add(bucket);
Object[] value = (Object[]) resolvePropertyFromPath(path.getPathElementsAsStringList(), buckets, "the_long_terms");
assertThat(value[0], equalTo(2.0));
}
use of org.opensearch.search.aggregations.support.AggregationPath in project OpenSearch by opensearch-project.
the class InternalMultiBucketAggregationTests method testResolveToKey.
public void testResolveToKey() {
AggregationPath path = AggregationPath.parse("_key");
List<LongTerms.Bucket> buckets = new ArrayList<>();
InternalAggregation agg = new InternalAvg("the_avg", 2, 1, DocValueFormat.RAW, Collections.emptyMap());
InternalAggregations internalAggregations = InternalAggregations.from(Collections.singletonList(agg));
LongTerms.Bucket bucket = new LongTerms.Bucket(19, 1, internalAggregations, false, 0, DocValueFormat.RAW);
buckets.add(bucket);
Object[] value = (Object[]) resolvePropertyFromPath(path.getPathElementsAsStringList(), buckets, "the_long_terms");
assertThat(value[0], equalTo(19L));
}
Aggregations