Search in sources :

Example 16 with Aggregation

use of org.opensearch.search.aggregations.Aggregation in project OpenSearch by opensearch-project.

the class ScriptedMetricIT method testMapReduceWithParams.

public void testMapReduceWithParams() {
    Map<String, Object> varsMap = new HashMap<>();
    varsMap.put("multiplier", 1);
    Map<String, Object> params = new HashMap<>();
    params.put("vars", varsMap);
    Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "state.list.add(vars.multiplier)", Collections.emptyMap());
    Script combineScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "no-op aggregation", Collections.emptyMap());
    Script reduceScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum all states' state.list values as a new aggregation", Collections.emptyMap());
    SearchResponse response = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(scriptedMetric("scripted").params(params).mapScript(mapScript).combineScript(combineScript).reduceScript(reduceScript)).get();
    assertSearchResponse(response);
    assertThat(response.getHits().getTotalHits().value, equalTo(numDocs));
    Aggregation aggregation = response.getAggregations().get("scripted");
    assertThat(aggregation, notNullValue());
    assertThat(aggregation, instanceOf(ScriptedMetric.class));
    ScriptedMetric scriptedMetricAggregation = (ScriptedMetric) aggregation;
    assertThat(scriptedMetricAggregation.getName(), equalTo("scripted"));
    assertThat(scriptedMetricAggregation.aggregation(), notNullValue());
    assertThat(scriptedMetricAggregation.aggregation(), instanceOf(ArrayList.class));
    List<?> aggregationList = (List<?>) scriptedMetricAggregation.aggregation();
    assertThat(aggregationList.size(), equalTo(1));
    Object object = aggregationList.get(0);
    assertThat(object, notNullValue());
    assertThat(object, instanceOf(Number.class));
    assertThat(((Number) object).longValue(), equalTo(numDocs));
}
Also used : Aggregation(org.opensearch.search.aggregations.Aggregation) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) Script(org.opensearch.script.Script) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 17 with Aggregation

use of org.opensearch.search.aggregations.Aggregation in project OpenSearch by opensearch-project.

the class ScriptedMetricIT method testMapCombineWithParams.

public void testMapCombineWithParams() {
    Map<String, Object> varsMap = new HashMap<>();
    varsMap.put("multiplier", 1);
    Map<String, Object> params = new HashMap<>();
    params.put("vars", varsMap);
    Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "state.list.add(1)", Collections.emptyMap());
    Script combineScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum state values as a new aggregation", Collections.emptyMap());
    Script reduceScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "no-op list aggregation", Collections.emptyMap());
    SearchResponse response = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(scriptedMetric("scripted").params(params).mapScript(mapScript).combineScript(combineScript).reduceScript(reduceScript)).get();
    assertSearchResponse(response);
    assertThat(response.getHits().getTotalHits().value, equalTo(numDocs));
    Aggregation aggregation = response.getAggregations().get("scripted");
    assertThat(aggregation, notNullValue());
    assertThat(aggregation, instanceOf(ScriptedMetric.class));
    ScriptedMetric scriptedMetricAggregation = (ScriptedMetric) aggregation;
    assertThat(scriptedMetricAggregation.getName(), equalTo("scripted"));
    assertThat(scriptedMetricAggregation.aggregation(), notNullValue());
    assertThat(scriptedMetricAggregation.aggregation(), instanceOf(ArrayList.class));
    List<?> aggregationList = (List<?>) scriptedMetricAggregation.aggregation();
    assertThat(aggregationList.size(), equalTo(getNumShards("idx").numPrimaries));
    long totalCount = 0;
    for (Object object : aggregationList) {
        assertThat(object, notNullValue());
        assertThat(object, instanceOf(List.class));
        List<?> list = (List<?>) object;
        for (Object o : list) {
            assertThat(o, notNullValue());
            assertThat(o, instanceOf(Number.class));
            Number numberValue = (Number) o;
            // A particular shard may not have any documents stored on it so
            // we have to assume the lower bound may be 0. The check at the
            // bottom of the test method will make sure the count is correct
            assertThat(numberValue.longValue(), allOf(greaterThanOrEqualTo(0L), lessThanOrEqualTo(numDocs)));
            totalCount += numberValue.longValue();
        }
    }
    assertThat(totalCount, equalTo(numDocs));
}
Also used : Script(org.opensearch.script.Script) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse) Aggregation(org.opensearch.search.aggregations.Aggregation) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) List(java.util.List) ArrayList(java.util.ArrayList)

Example 18 with Aggregation

use of org.opensearch.search.aggregations.Aggregation in project OpenSearch by opensearch-project.

the class ScriptedMetricIT method testInitMapCombineWithParams.

public void testInitMapCombineWithParams() {
    Map<String, Object> varsMap = new HashMap<>();
    varsMap.put("multiplier", 1);
    Map<String, Object> params = new HashMap<>();
    params.put("vars", varsMap);
    Script initScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "vars.multiplier = 3", Collections.emptyMap());
    Script mapScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "state.list.add(vars.multiplier)", Collections.emptyMap());
    Script combineScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "sum state values as a new aggregation", Collections.emptyMap());
    Script reduceScript = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "no-op list aggregation", Collections.emptyMap());
    SearchResponse response = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(scriptedMetric("scripted").params(params).initScript(initScript).mapScript(mapScript).combineScript(combineScript).reduceScript(reduceScript)).get();
    assertSearchResponse(response);
    assertThat(response.getHits().getTotalHits().value, equalTo(numDocs));
    Aggregation aggregation = response.getAggregations().get("scripted");
    assertThat(aggregation, notNullValue());
    assertThat(aggregation, instanceOf(ScriptedMetric.class));
    ScriptedMetric scriptedMetricAggregation = (ScriptedMetric) aggregation;
    assertThat(scriptedMetricAggregation.getName(), equalTo("scripted"));
    assertThat(scriptedMetricAggregation.aggregation(), notNullValue());
    assertThat(scriptedMetricAggregation.aggregation(), instanceOf(ArrayList.class));
    List<?> aggregationList = (List<?>) scriptedMetricAggregation.aggregation();
    assertThat(aggregationList.size(), equalTo(getNumShards("idx").numPrimaries));
    long totalCount = 0;
    for (Object object : aggregationList) {
        assertThat(object, notNullValue());
        assertThat(object, instanceOf(List.class));
        List<?> list = (List<?>) object;
        for (Object o : list) {
            assertThat(o, notNullValue());
            assertThat(o, instanceOf(Number.class));
            Number numberValue = (Number) o;
            // A particular shard may not have any documents stored on it so
            // we have to assume the lower bound may be 0. The check at the
            // bottom of the test method will make sure the count is correct
            assertThat(numberValue.longValue(), allOf(greaterThanOrEqualTo(0L), lessThanOrEqualTo(numDocs * 3)));
            totalCount += numberValue.longValue();
        }
    }
    assertThat(totalCount, equalTo(numDocs * 3));
}
Also used : Script(org.opensearch.script.Script) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse) Aggregation(org.opensearch.search.aggregations.Aggregation) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) List(java.util.List) ArrayList(java.util.ArrayList)

Example 19 with Aggregation

use of org.opensearch.search.aggregations.Aggregation in project OpenSearch by opensearch-project.

the class InternalAggregationTestCase method parseAndAssert.

@SuppressWarnings("unchecked")
protected <P extends ParsedAggregation> P parseAndAssert(final InternalAggregation aggregation, final boolean shuffled, final boolean addRandomFields) throws IOException {
    final ToXContent.Params params = new ToXContent.MapParams(singletonMap(RestSearchAction.TYPED_KEYS_PARAM, "true"));
    final XContentType xContentType = randomFrom(XContentType.values());
    final boolean humanReadable = randomBoolean();
    final BytesReference originalBytes;
    if (shuffled) {
        originalBytes = toShuffledXContent(aggregation, xContentType, params, humanReadable);
    } else {
        originalBytes = toXContent(aggregation, xContentType, params, humanReadable);
    }
    BytesReference mutated;
    if (addRandomFields) {
        /*
             * - we don't add to the root object because it should only contain
             * the named aggregation to test - we don't want to insert into the
             * "meta" object, because we pass on everything we find there
             *
             * - we don't want to directly insert anything random into "buckets"
             * objects, they are used with "keyed" aggregations and contain
             * named bucket objects. Any new named object on this level should
             * also be a bucket and be parsed as such.
             *
             * we also exclude top_hits that contain SearchHits, as all unknown fields
             * on a root level of SearchHit are interpreted as meta-fields and will be kept.
             */
        Predicate<String> basicExcludes = path -> path.isEmpty() || path.endsWith(Aggregation.CommonFields.META.getPreferredName()) || path.endsWith(Aggregation.CommonFields.BUCKETS.getPreferredName()) || path.contains("top_hits");
        Predicate<String> excludes = basicExcludes.or(excludePathsFromXContentInsertion());
        mutated = XContentTestUtils.insertRandomFields(xContentType, originalBytes, excludes, random());
    } else {
        mutated = originalBytes;
    }
    SetOnce<Aggregation> parsedAggregation = new SetOnce<>();
    try (XContentParser parser = createParser(xContentType.xContent(), mutated)) {
        assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
        assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
        assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
        XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, parsedAggregation::set);
        assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
        assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
        assertNull(parser.nextToken());
        Aggregation agg = parsedAggregation.get();
        assertEquals(aggregation.getName(), agg.getName());
        assertEquals(aggregation.getMetadata(), agg.getMetadata());
        assertTrue(agg instanceof ParsedAggregation);
        assertEquals(aggregation.getType(), agg.getType());
        BytesReference parsedBytes = toXContent(agg, xContentType, params, humanReadable);
        OpenSearchAssertions.assertToXContentEquivalent(originalBytes, parsedBytes, xContentType);
        return (P) agg;
    }
}
Also used : ToXContent(org.opensearch.common.xcontent.ToXContent) BytesReference(org.opensearch.common.bytes.BytesReference) InternalSampler(org.opensearch.search.aggregations.bucket.sampler.InternalSampler) ParsedMax(org.opensearch.search.aggregations.metrics.ParsedMax) ParsedDateRange(org.opensearch.search.aggregations.bucket.range.ParsedDateRange) GeoDistanceAggregationBuilder(org.opensearch.search.aggregations.bucket.range.GeoDistanceAggregationBuilder) ParsedSignificantLongTerms(org.opensearch.search.aggregations.bucket.terms.ParsedSignificantLongTerms) ParsedBucketMetricValue(org.opensearch.search.aggregations.pipeline.ParsedBucketMetricValue) GeoBoundsAggregationBuilder(org.opensearch.search.aggregations.metrics.GeoBoundsAggregationBuilder) ParsedDateHistogram(org.opensearch.search.aggregations.bucket.histogram.ParsedDateHistogram) IpRangeAggregationBuilder(org.opensearch.search.aggregations.bucket.range.IpRangeAggregationBuilder) StringRareTerms(org.opensearch.search.aggregations.bucket.terms.StringRareTerms) ParsedGlobal(org.opensearch.search.aggregations.bucket.global.ParsedGlobal) MockBigArrays(org.opensearch.common.util.MockBigArrays) ParsedMin(org.opensearch.search.aggregations.metrics.ParsedMin) ParsedStringRareTerms(org.opensearch.search.aggregations.bucket.terms.ParsedStringRareTerms) Map(java.util.Map) ParsedSum(org.opensearch.search.aggregations.metrics.ParsedSum) InternalHDRPercentiles(org.opensearch.search.aggregations.metrics.InternalHDRPercentiles) FilterAggregationBuilder(org.opensearch.search.aggregations.bucket.filter.FilterAggregationBuilder) ScriptService(org.opensearch.script.ScriptService) LongRareTerms(org.opensearch.search.aggregations.bucket.terms.LongRareTerms) ParsedSimpleValue(org.opensearch.search.aggregations.pipeline.ParsedSimpleValue) ParsedHDRPercentiles(org.opensearch.search.aggregations.metrics.ParsedHDRPercentiles) LongTerms(org.opensearch.search.aggregations.bucket.terms.LongTerms) GlobalAggregationBuilder(org.opensearch.search.aggregations.bucket.global.GlobalAggregationBuilder) VariableWidthHistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.VariableWidthHistogramAggregationBuilder) DerivativePipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder) Settings(org.opensearch.common.settings.Settings) InternalTDigestPercentileRanks(org.opensearch.search.aggregations.metrics.InternalTDigestPercentileRanks) ParsedValueCount(org.opensearch.search.aggregations.metrics.ParsedValueCount) CardinalityAggregationBuilder(org.opensearch.search.aggregations.metrics.CardinalityAggregationBuilder) GeoHashGridAggregationBuilder(org.opensearch.search.aggregations.bucket.geogrid.GeoHashGridAggregationBuilder) ParsedGeoTileGrid(org.opensearch.search.aggregations.bucket.geogrid.ParsedGeoTileGrid) SumBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.SumBucketPipelineAggregationBuilder) ValueCountAggregationBuilder(org.opensearch.search.aggregations.metrics.ValueCountAggregationBuilder) XContentParserUtils(org.opensearch.common.xcontent.XContentParserUtils) XContentType(org.opensearch.common.xcontent.XContentType) MinAggregationBuilder(org.opensearch.search.aggregations.metrics.MinAggregationBuilder) ParsedNested(org.opensearch.search.aggregations.bucket.nested.ParsedNested) ParsedAdjacencyMatrix(org.opensearch.search.aggregations.bucket.adjacency.ParsedAdjacencyMatrix) ParsedDerivative(org.opensearch.search.aggregations.pipeline.ParsedDerivative) ReverseNestedAggregationBuilder(org.opensearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder) MissingAggregationBuilder(org.opensearch.search.aggregations.bucket.missing.MissingAggregationBuilder) InternalMultiBucketAggregation.countInnerBucket(org.opensearch.search.aggregations.InternalMultiBucketAggregation.countInnerBucket) ParsedTDigestPercentiles(org.opensearch.search.aggregations.metrics.ParsedTDigestPercentiles) StringTerms(org.opensearch.search.aggregations.bucket.terms.StringTerms) ReduceContext(org.opensearch.search.aggregations.InternalAggregation.ReduceContext) DateHistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) MaxBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.MaxBucketPipelineAggregationBuilder) ParseField(org.opensearch.common.ParseField) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) RestSearchAction(org.opensearch.rest.action.search.RestSearchAction) XContentHelper.toXContent(org.opensearch.common.xcontent.XContentHelper.toXContent) ParsedAggregation(org.opensearch.search.aggregations.ParsedAggregation) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ParsedWeightedAvg(org.opensearch.search.aggregations.metrics.ParsedWeightedAvg) SetOnce(org.apache.lucene.util.SetOnce) ParsedReverseNested(org.opensearch.search.aggregations.bucket.nested.ParsedReverseNested) SearchPlugin(org.opensearch.plugins.SearchPlugin) IOException(java.io.IOException) ParsedExtendedStats(org.opensearch.search.aggregations.metrics.ParsedExtendedStats) Plugin(org.opensearch.plugins.Plugin) MaxAggregationBuilder(org.opensearch.search.aggregations.metrics.MaxAggregationBuilder) ParsedStats(org.opensearch.search.aggregations.metrics.ParsedStats) StatsAggregationBuilder(org.opensearch.search.aggregations.metrics.StatsAggregationBuilder) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ParsedScriptedMetric(org.opensearch.search.aggregations.metrics.ParsedScriptedMetric) ParsedStatsBucket(org.opensearch.search.aggregations.pipeline.ParsedStatsBucket) SumAggregationBuilder(org.opensearch.search.aggregations.metrics.SumAggregationBuilder) SearchModule(org.opensearch.search.SearchModule) Aggregation(org.opensearch.search.aggregations.Aggregation) RangeAggregationBuilder(org.opensearch.search.aggregations.bucket.range.RangeAggregationBuilder) ToXContent(org.opensearch.common.xcontent.ToXContent) ParsedStringTerms(org.opensearch.search.aggregations.bucket.terms.ParsedStringTerms) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) ParsedGeoCentroid(org.opensearch.search.aggregations.metrics.ParsedGeoCentroid) CircuitBreaker(org.opensearch.common.breaker.CircuitBreaker) XContentParser(org.opensearch.common.xcontent.XContentParser) ExtendedStatsAggregationBuilder(org.opensearch.search.aggregations.metrics.ExtendedStatsAggregationBuilder) ScriptedMetricAggregationBuilder(org.opensearch.search.aggregations.metrics.ScriptedMetricAggregationBuilder) ParsedTDigestPercentileRanks(org.opensearch.search.aggregations.metrics.ParsedTDigestPercentileRanks) ParsedAvg(org.opensearch.search.aggregations.metrics.ParsedAvg) AvgBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.AvgBucketPipelineAggregationBuilder) DateRangeAggregationBuilder(org.opensearch.search.aggregations.bucket.range.DateRangeAggregationBuilder) MedianAbsoluteDeviationAggregationBuilder(org.opensearch.search.aggregations.metrics.MedianAbsoluteDeviationAggregationBuilder) MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) ParsedFilter(org.opensearch.search.aggregations.bucket.filter.ParsedFilter) InternalTDigestPercentiles(org.opensearch.search.aggregations.metrics.InternalTDigestPercentiles) ParsedFilters(org.opensearch.search.aggregations.bucket.filter.ParsedFilters) ParsedSampler(org.opensearch.search.aggregations.bucket.sampler.ParsedSampler) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) ParsedComposite(org.opensearch.search.aggregations.bucket.composite.ParsedComposite) ContextParser(org.opensearch.common.xcontent.ContextParser) ParsedVariableWidthHistogram(org.opensearch.search.aggregations.bucket.histogram.ParsedVariableWidthHistogram) ParsedMultiTerms(org.opensearch.search.aggregations.bucket.terms.ParsedMultiTerms) WeightedAvgAggregationBuilder(org.opensearch.search.aggregations.metrics.WeightedAvgAggregationBuilder) FiltersAggregationBuilder(org.opensearch.search.aggregations.bucket.filter.FiltersAggregationBuilder) InternalHDRPercentileRanks(org.opensearch.search.aggregations.metrics.InternalHDRPercentileRanks) Collectors(java.util.stream.Collectors) OpenSearchAssertions(org.opensearch.test.hamcrest.OpenSearchAssertions) MultiBucketConsumer(org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer) TopHitsAggregationBuilder(org.opensearch.search.aggregations.metrics.TopHitsAggregationBuilder) List(java.util.List) ParsedBinaryRange(org.opensearch.search.aggregations.bucket.range.ParsedBinaryRange) PipelineAggregator(org.opensearch.search.aggregations.pipeline.PipelineAggregator) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PercentilesBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.PercentilesBucketPipelineAggregationBuilder) BigArrays(org.opensearch.common.util.BigArrays) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) MultiBucketConsumerService(org.opensearch.search.aggregations.MultiBucketConsumerService) ParsedTopHits(org.opensearch.search.aggregations.metrics.ParsedTopHits) DoubleTerms(org.opensearch.search.aggregations.bucket.terms.DoubleTerms) ParsedRange(org.opensearch.search.aggregations.bucket.range.ParsedRange) InternalSimpleValue(org.opensearch.search.aggregations.pipeline.InternalSimpleValue) BytesReference(org.opensearch.common.bytes.BytesReference) ParsedPercentilesBucket(org.opensearch.search.aggregations.pipeline.ParsedPercentilesBucket) HistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder) ParsedCardinality(org.opensearch.search.aggregations.metrics.ParsedCardinality) DocValueFormat(org.opensearch.search.DocValueFormat) AvgAggregationBuilder(org.opensearch.search.aggregations.metrics.AvgAggregationBuilder) ParsedAutoDateHistogram(org.opensearch.search.aggregations.bucket.histogram.ParsedAutoDateHistogram) HashMap(java.util.HashMap) AutoDateHistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.AutoDateHistogramAggregationBuilder) ParsedHistogram(org.opensearch.search.aggregations.bucket.histogram.ParsedHistogram) ParsedGeoDistance(org.opensearch.search.aggregations.bucket.range.ParsedGeoDistance) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) CompositeAggregationBuilder(org.opensearch.search.aggregations.bucket.composite.CompositeAggregationBuilder) PipelineTree(org.opensearch.search.aggregations.pipeline.PipelineAggregator.PipelineTree) GeoCentroidAggregationBuilder(org.opensearch.search.aggregations.metrics.GeoCentroidAggregationBuilder) ParsedSignificantStringTerms(org.opensearch.search.aggregations.bucket.terms.ParsedSignificantStringTerms) ParsedExtendedStatsBucket(org.opensearch.search.aggregations.pipeline.ParsedExtendedStatsBucket) ParsedGeoBounds(org.opensearch.search.aggregations.metrics.ParsedGeoBounds) Collections.singletonMap(java.util.Collections.singletonMap) ParsedLongRareTerms(org.opensearch.search.aggregations.bucket.terms.ParsedLongRareTerms) ParsedMedianAbsoluteDeviation(org.opensearch.search.aggregations.metrics.ParsedMedianAbsoluteDeviation) SignificantStringTerms(org.opensearch.search.aggregations.bucket.terms.SignificantStringTerms) ParsedLongTerms(org.opensearch.search.aggregations.bucket.terms.ParsedLongTerms) ParsedDoubleTerms(org.opensearch.search.aggregations.bucket.terms.ParsedDoubleTerms) GeoTileGridAggregationBuilder(org.opensearch.search.aggregations.bucket.geogrid.GeoTileGridAggregationBuilder) Collections.emptyMap(java.util.Collections.emptyMap) AdjacencyMatrixAggregationBuilder(org.opensearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder) ParsedHDRPercentileRanks(org.opensearch.search.aggregations.metrics.ParsedHDRPercentileRanks) MultiTermsAggregationBuilder(org.opensearch.search.aggregations.bucket.terms.MultiTermsAggregationBuilder) SignificantLongTerms(org.opensearch.search.aggregations.bucket.terms.SignificantLongTerms) ParsedGeoHashGrid(org.opensearch.search.aggregations.bucket.geogrid.ParsedGeoHashGrid) StatsBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.StatsBucketPipelineAggregationBuilder) InternalBucketMetricValue(org.opensearch.search.aggregations.pipeline.InternalBucketMetricValue) NestedAggregationBuilder(org.opensearch.search.aggregations.bucket.nested.NestedAggregationBuilder) Comparator(java.util.Comparator) ParsedMissing(org.opensearch.search.aggregations.bucket.missing.ParsedMissing) Collections(java.util.Collections) ExtendedStatsBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregationBuilder) SetOnce(org.apache.lucene.util.SetOnce) ParsedAggregation(org.opensearch.search.aggregations.ParsedAggregation) ParsedAggregation(org.opensearch.search.aggregations.ParsedAggregation) Aggregation(org.opensearch.search.aggregations.Aggregation) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) XContentType(org.opensearch.common.xcontent.XContentType) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 20 with Aggregation

use of org.opensearch.search.aggregations.Aggregation in project OpenSearch by opensearch-project.

the class InternalAggregationTestCase method randomPipelineTree.

public static PipelineAggregator.PipelineTree randomPipelineTree(InternalAggregation aggregation) {
    Map<String, PipelineTree> subTree = new HashMap<>();
    aggregation.forEachBucket(bucketAggs -> {
        for (Aggregation subAgg : bucketAggs) {
            if (subTree.containsKey(subAgg.getName())) {
                continue;
            }
            subTree.put(subAgg.getName(), randomPipelineTree((InternalAggregation) subAgg));
        }
    });
    return new PipelineAggregator.PipelineTree(emptyMap(), randomPipelineAggregators());
}
Also used : ParsedAggregation(org.opensearch.search.aggregations.ParsedAggregation) Aggregation(org.opensearch.search.aggregations.Aggregation) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) HashMap(java.util.HashMap) PipelineTree(org.opensearch.search.aggregations.pipeline.PipelineAggregator.PipelineTree)

Aggregations

Aggregation (org.opensearch.search.aggregations.Aggregation)54 SearchResponse (org.opensearch.action.search.SearchResponse)31 HashMap (java.util.HashMap)30 List (java.util.List)30 ArrayList (java.util.ArrayList)29 Map (java.util.Map)20 InternalAggregation (org.opensearch.search.aggregations.InternalAggregation)19 Aggregations (org.opensearch.search.aggregations.Aggregations)18 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)16 Matchers.containsString (org.hamcrest.Matchers.containsString)14 IOException (java.io.IOException)13 Collections (java.util.Collections)13 ActionListener (org.opensearch.action.ActionListener)13 NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)13 MultiBucketsAggregation (org.opensearch.search.aggregations.bucket.MultiBucketsAggregation)13 Terms (org.opensearch.search.aggregations.bucket.terms.Terms)13 Collectors (java.util.stream.Collectors)12 Script (org.opensearch.script.Script)12 Arrays (java.util.Arrays)11 SearchRequest (org.opensearch.action.search.SearchRequest)11