use of org.opensearch.search.aggregations.bucket.MultiBucketsAggregation in project OpenSearch by opensearch-project.
the class BucketHelpersTests method testReturnMultiValueObject.
public void testReturnMultiValueObject() {
MultiBucketsAggregation agg = new MultiBucketsAggregation() {
@Override
public List<? extends Bucket> getBuckets() {
return null;
}
@Override
public String getName() {
return "foo";
}
@Override
public String getType() {
return null;
}
@Override
public Map<String, Object> getMetadata() {
return null;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return null;
}
};
InternalMultiBucketAggregation.InternalBucket bucket = new InternalMultiBucketAggregation.InternalBucket() {
@Override
public void writeTo(StreamOutput out) throws IOException {
}
@Override
public Object getKey() {
return null;
}
@Override
public String getKeyAsString() {
return null;
}
@Override
public long getDocCount() {
return 0;
}
@Override
public Aggregations getAggregations() {
return null;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return null;
}
@Override
public Object getProperty(String containingAggName, List<String> path) {
return mock(InternalTDigestPercentiles.class);
}
};
AggregationExecutionException e = expectThrows(AggregationExecutionException.class, () -> BucketHelpers.resolveBucketValue(agg, bucket, "foo>bar", BucketHelpers.GapPolicy.SKIP));
assertThat(e.getMessage(), equalTo("buckets_path must reference either a number value or a single value numeric " + "metric aggregation, but [foo] contains multiple values. Please specify which to use."));
}
use of org.opensearch.search.aggregations.bucket.MultiBucketsAggregation in project OpenSearch by opensearch-project.
the class CCSDuelIT method assertAggs.
private static void assertAggs(SearchResponse response) {
assertMultiClusterSearchResponse(response);
assertThat(response.getHits().getTotalHits().value, greaterThan(0L));
assertEquals(0, response.getHits().getHits().length);
assertNull(response.getSuggest());
assertNotNull(response.getAggregations());
List<Aggregation> aggregations = response.getAggregations().asList();
for (Aggregation aggregation : aggregations) {
if (aggregation instanceof MultiBucketsAggregation) {
MultiBucketsAggregation multiBucketsAggregation = (MultiBucketsAggregation) aggregation;
assertThat("agg " + multiBucketsAggregation.getName() + " has 0 buckets", multiBucketsAggregation.getBuckets().size(), greaterThan(0));
}
}
}
use of org.opensearch.search.aggregations.bucket.MultiBucketsAggregation in project OpenSearch by opensearch-project.
the class BucketHelpersTests method testReturnsObjectArray.
public void testReturnsObjectArray() {
MultiBucketsAggregation agg = new MultiBucketsAggregation() {
@Override
public List<? extends Bucket> getBuckets() {
return null;
}
@Override
public String getName() {
return "foo";
}
@Override
public String getType() {
return null;
}
@Override
public Map<String, Object> getMetadata() {
return null;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return null;
}
};
InternalMultiBucketAggregation.InternalBucket bucket = new InternalMultiBucketAggregation.InternalBucket() {
@Override
public void writeTo(StreamOutput out) throws IOException {
}
@Override
public Object getKey() {
return null;
}
@Override
public String getKeyAsString() {
return null;
}
@Override
public long getDocCount() {
return 0;
}
@Override
public Aggregations getAggregations() {
return null;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return null;
}
@Override
public Object getProperty(String containingAggName, List<String> path) {
return new Object[0];
}
};
AggregationExecutionException e = expectThrows(AggregationExecutionException.class, () -> BucketHelpers.resolveBucketValue(agg, bucket, "foo>bar", BucketHelpers.GapPolicy.SKIP));
assertThat(e.getMessage(), equalTo("buckets_path must reference either a number value or a single value numeric " + "metric aggregation, got: [Object[]] at aggregation [foo]"));
}
use of org.opensearch.search.aggregations.bucket.MultiBucketsAggregation in project OpenSearch by opensearch-project.
the class InternalMultiBucketAggregationTestCase method assertMultiBucketsAggregations.
private void assertMultiBucketsAggregations(Aggregation expected, Aggregation actual, boolean checkOrder) {
assertTrue(expected instanceof MultiBucketsAggregation);
MultiBucketsAggregation expectedMultiBucketsAggregation = (MultiBucketsAggregation) expected;
assertTrue(actual instanceof MultiBucketsAggregation);
MultiBucketsAggregation actualMultiBucketsAggregation = (MultiBucketsAggregation) actual;
assertMultiBucketsAggregation(expectedMultiBucketsAggregation, actualMultiBucketsAggregation, checkOrder);
List<? extends MultiBucketsAggregation.Bucket> expectedBuckets = expectedMultiBucketsAggregation.getBuckets();
List<? extends MultiBucketsAggregation.Bucket> actualBuckets = actualMultiBucketsAggregation.getBuckets();
assertEquals(expectedBuckets.size(), actualBuckets.size());
if (checkOrder) {
Iterator<? extends MultiBucketsAggregation.Bucket> expectedIt = expectedBuckets.iterator();
Iterator<? extends MultiBucketsAggregation.Bucket> actualIt = actualBuckets.iterator();
while (expectedIt.hasNext()) {
MultiBucketsAggregation.Bucket expectedBucket = expectedIt.next();
MultiBucketsAggregation.Bucket actualBucket = actualIt.next();
assertBucket(expectedBucket, actualBucket, true);
}
} else {
for (MultiBucketsAggregation.Bucket expectedBucket : expectedBuckets) {
final Object expectedKey = expectedBucket.getKey();
boolean found = false;
for (MultiBucketsAggregation.Bucket actualBucket : actualBuckets) {
final Object actualKey = actualBucket.getKey();
if ((actualKey != null && actualKey.equals(expectedKey)) || (actualKey == null && expectedKey == null)) {
found = true;
assertBucket(expectedBucket, actualBucket, false);
break;
}
}
assertTrue("Failed to find bucket with key [" + expectedBucket.getKey() + "]", found);
}
}
}
Aggregations