Search in sources :

Example 6 with AggregationPath

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));
}
Also used : InternalAvg(org.opensearch.search.aggregations.metrics.InternalAvg) ArrayList(java.util.ArrayList) LongTerms(org.opensearch.search.aggregations.bucket.terms.LongTerms) AggregationPath(org.opensearch.search.aggregations.support.AggregationPath)

Example 7 with AggregationPath

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]"));
}
Also used : InternalAvg(org.opensearch.search.aggregations.metrics.InternalAvg) ArrayList(java.util.ArrayList) LongTerms(org.opensearch.search.aggregations.bucket.terms.LongTerms) AggregationPath(org.opensearch.search.aggregations.support.AggregationPath)

Example 8 with AggregationPath

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));
}
Also used : InternalAvg(org.opensearch.search.aggregations.metrics.InternalAvg) ArrayList(java.util.ArrayList) LongTerms(org.opensearch.search.aggregations.bucket.terms.LongTerms) AggregationPath(org.opensearch.search.aggregations.support.AggregationPath)

Example 9 with AggregationPath

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));
}
Also used : InternalAvg(org.opensearch.search.aggregations.metrics.InternalAvg) ArrayList(java.util.ArrayList) LongTerms(org.opensearch.search.aggregations.bucket.terms.LongTerms) AggregationPath(org.opensearch.search.aggregations.support.AggregationPath)

Aggregations

ArrayList (java.util.ArrayList)9 LongTerms (org.opensearch.search.aggregations.bucket.terms.LongTerms)9 InternalAvg (org.opensearch.search.aggregations.metrics.InternalAvg)9 AggregationPath (org.opensearch.search.aggregations.support.AggregationPath)9 BytesRef (org.apache.lucene.util.BytesRef)2 InternalTerms (org.opensearch.search.aggregations.bucket.terms.InternalTerms)2 StringTerms (org.opensearch.search.aggregations.bucket.terms.StringTerms)2