Search in sources :

Example 1 with MultiBucketsAggregation

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."));
}
Also used : MultiBucketsAggregation(org.opensearch.search.aggregations.bucket.MultiBucketsAggregation) List(java.util.List) InternalMultiBucketAggregation(org.opensearch.search.aggregations.InternalMultiBucketAggregation) StreamOutput(org.opensearch.common.io.stream.StreamOutput) AggregationExecutionException(org.opensearch.search.aggregations.AggregationExecutionException) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 2 with MultiBucketsAggregation

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));
        }
    }
}
Also used : Aggregation(org.opensearch.search.aggregations.Aggregation) MultiBucketsAggregation(org.opensearch.search.aggregations.bucket.MultiBucketsAggregation) MultiBucketsAggregation(org.opensearch.search.aggregations.bucket.MultiBucketsAggregation)

Example 3 with MultiBucketsAggregation

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]"));
}
Also used : MultiBucketsAggregation(org.opensearch.search.aggregations.bucket.MultiBucketsAggregation) List(java.util.List) InternalMultiBucketAggregation(org.opensearch.search.aggregations.InternalMultiBucketAggregation) StreamOutput(org.opensearch.common.io.stream.StreamOutput) AggregationExecutionException(org.opensearch.search.aggregations.AggregationExecutionException) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 4 with MultiBucketsAggregation

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);
        }
    }
}
Also used : MultiBucketsAggregation(org.opensearch.search.aggregations.bucket.MultiBucketsAggregation)

Aggregations

MultiBucketsAggregation (org.opensearch.search.aggregations.bucket.MultiBucketsAggregation)4 List (java.util.List)2 StreamOutput (org.opensearch.common.io.stream.StreamOutput)2 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)2 AggregationExecutionException (org.opensearch.search.aggregations.AggregationExecutionException)2 InternalMultiBucketAggregation (org.opensearch.search.aggregations.InternalMultiBucketAggregation)2 Aggregation (org.opensearch.search.aggregations.Aggregation)1