Search in sources :

Example 26 with Aggregation

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

the class DlsTermLookupQueryTest method getDefaultNamedXContents.

public static List<NamedXContentRegistry.Entry> getDefaultNamedXContents() {
    Map<String, ContextParser<Object, ? extends Aggregation>> map = new HashMap<>();
    map.put(TopHitsAggregationBuilder.NAME, (p, c) -> ParsedTopHits.fromXContent(p, (String) c));
    map.put(StringTerms.NAME, (p, c) -> ParsedStringTerms.fromXContent(p, (String) c));
    List<NamedXContentRegistry.Entry> entries = map.entrySet().stream().map(entry -> new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(entry.getKey()), entry.getValue())).collect(Collectors.toList());
    return entries;
}
Also used : Aggregation(org.opensearch.search.aggregations.Aggregation) Bucket(org.opensearch.search.aggregations.bucket.terms.Terms.Bucket) Arrays(java.util.Arrays) MultiGetResponse(org.opensearch.action.get.MultiGetResponse) Aggregation(org.opensearch.search.aggregations.Aggregation) StringTerms(org.opensearch.search.aggregations.bucket.terms.StringTerms) ParsedStringTerms(org.opensearch.search.aggregations.bucket.terms.ParsedStringTerms) HashMap(java.util.HashMap) Aggregations(org.opensearch.search.aggregations.Aggregations) ParseField(org.opensearch.common.ParseField) XContentParser(org.opensearch.common.xcontent.XContentParser) Map(java.util.Map) SearchResponse(org.opensearch.action.search.SearchResponse) GetResponse(org.opensearch.action.get.GetResponse) DlsTermsLookupAsserts.assertAccessCodesMatch(org.opensearch.security.dlic.dlsfls.DlsTermsLookupAsserts.assertAccessCodesMatch) CreateIndexRequest(org.opensearch.action.admin.indices.create.CreateIndexRequest) Client(org.opensearch.client.Client) Item(org.opensearch.action.search.MultiSearchResponse.Item) SearchHit(org.opensearch.search.SearchHit) PutMappingRequest(org.opensearch.action.admin.indices.mapping.put.PutMappingRequest) ContextParser(org.opensearch.common.xcontent.ContextParser) LoggingDeprecationHandler(org.opensearch.common.xcontent.LoggingDeprecationHandler) Set(java.util.Set) DynamicSecurityConfig(org.opensearch.security.test.DynamicSecurityConfig) Test(org.junit.Test) Terms(org.opensearch.search.aggregations.bucket.terms.Terms) Collectors(java.util.stream.Collectors) MultiSearchResponse(org.opensearch.action.search.MultiSearchResponse) List(java.util.List) MultiGetItemResponse(org.opensearch.action.get.MultiGetItemResponse) TopHitsAggregationBuilder(org.opensearch.search.aggregations.metrics.TopHitsAggregationBuilder) HttpResponse(org.opensearch.security.test.helper.rest.RestHelper.HttpResponse) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) XContentType(org.opensearch.common.xcontent.XContentType) Assert(org.junit.Assert) IndexRequest(org.opensearch.action.index.IndexRequest) ParsedTopHits(org.opensearch.search.aggregations.metrics.ParsedTopHits) RefreshPolicy(org.opensearch.action.support.WriteRequest.RefreshPolicy) ContextParser(org.opensearch.common.xcontent.ContextParser) HashMap(java.util.HashMap) ParseField(org.opensearch.common.ParseField)

Example 27 with Aggregation

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

the class RestHighLevelClient method getDefaultNamedXContents.

static List<NamedXContentRegistry.Entry> getDefaultNamedXContents() {
    Map<String, ContextParser<Object, ? extends Aggregation>> map = new HashMap<>();
    map.put(CardinalityAggregationBuilder.NAME, (p, c) -> ParsedCardinality.fromXContent(p, (String) c));
    map.put(InternalHDRPercentiles.NAME, (p, c) -> ParsedHDRPercentiles.fromXContent(p, (String) c));
    map.put(InternalHDRPercentileRanks.NAME, (p, c) -> ParsedHDRPercentileRanks.fromXContent(p, (String) c));
    map.put(InternalTDigestPercentiles.NAME, (p, c) -> ParsedTDigestPercentiles.fromXContent(p, (String) c));
    map.put(InternalTDigestPercentileRanks.NAME, (p, c) -> ParsedTDigestPercentileRanks.fromXContent(p, (String) c));
    map.put(PercentilesBucketPipelineAggregationBuilder.NAME, (p, c) -> ParsedPercentilesBucket.fromXContent(p, (String) c));
    map.put(MedianAbsoluteDeviationAggregationBuilder.NAME, (p, c) -> ParsedMedianAbsoluteDeviation.fromXContent(p, (String) c));
    map.put(MinAggregationBuilder.NAME, (p, c) -> ParsedMin.fromXContent(p, (String) c));
    map.put(MaxAggregationBuilder.NAME, (p, c) -> ParsedMax.fromXContent(p, (String) c));
    map.put(SumAggregationBuilder.NAME, (p, c) -> ParsedSum.fromXContent(p, (String) c));
    map.put(AvgAggregationBuilder.NAME, (p, c) -> ParsedAvg.fromXContent(p, (String) c));
    map.put(WeightedAvgAggregationBuilder.NAME, (p, c) -> ParsedWeightedAvg.fromXContent(p, (String) c));
    map.put(ValueCountAggregationBuilder.NAME, (p, c) -> ParsedValueCount.fromXContent(p, (String) c));
    map.put(InternalSimpleValue.NAME, (p, c) -> ParsedSimpleValue.fromXContent(p, (String) c));
    map.put(DerivativePipelineAggregationBuilder.NAME, (p, c) -> ParsedDerivative.fromXContent(p, (String) c));
    map.put(InternalBucketMetricValue.NAME, (p, c) -> ParsedBucketMetricValue.fromXContent(p, (String) c));
    map.put(StatsAggregationBuilder.NAME, (p, c) -> ParsedStats.fromXContent(p, (String) c));
    map.put(StatsBucketPipelineAggregationBuilder.NAME, (p, c) -> ParsedStatsBucket.fromXContent(p, (String) c));
    map.put(ExtendedStatsAggregationBuilder.NAME, (p, c) -> ParsedExtendedStats.fromXContent(p, (String) c));
    map.put(ExtendedStatsBucketPipelineAggregationBuilder.NAME, (p, c) -> ParsedExtendedStatsBucket.fromXContent(p, (String) c));
    map.put(GeoBoundsAggregationBuilder.NAME, (p, c) -> ParsedGeoBounds.fromXContent(p, (String) c));
    map.put(GeoCentroidAggregationBuilder.NAME, (p, c) -> ParsedGeoCentroid.fromXContent(p, (String) c));
    map.put(HistogramAggregationBuilder.NAME, (p, c) -> ParsedHistogram.fromXContent(p, (String) c));
    map.put(DateHistogramAggregationBuilder.NAME, (p, c) -> ParsedDateHistogram.fromXContent(p, (String) c));
    map.put(AutoDateHistogramAggregationBuilder.NAME, (p, c) -> ParsedAutoDateHistogram.fromXContent(p, (String) c));
    map.put(VariableWidthHistogramAggregationBuilder.NAME, (p, c) -> ParsedVariableWidthHistogram.fromXContent(p, (String) c));
    map.put(StringTerms.NAME, (p, c) -> ParsedStringTerms.fromXContent(p, (String) c));
    map.put(LongTerms.NAME, (p, c) -> ParsedLongTerms.fromXContent(p, (String) c));
    map.put(DoubleTerms.NAME, (p, c) -> ParsedDoubleTerms.fromXContent(p, (String) c));
    map.put(LongRareTerms.NAME, (p, c) -> ParsedLongRareTerms.fromXContent(p, (String) c));
    map.put(StringRareTerms.NAME, (p, c) -> ParsedStringRareTerms.fromXContent(p, (String) c));
    map.put(MissingAggregationBuilder.NAME, (p, c) -> ParsedMissing.fromXContent(p, (String) c));
    map.put(NestedAggregationBuilder.NAME, (p, c) -> ParsedNested.fromXContent(p, (String) c));
    map.put(ReverseNestedAggregationBuilder.NAME, (p, c) -> ParsedReverseNested.fromXContent(p, (String) c));
    map.put(GlobalAggregationBuilder.NAME, (p, c) -> ParsedGlobal.fromXContent(p, (String) c));
    map.put(FilterAggregationBuilder.NAME, (p, c) -> ParsedFilter.fromXContent(p, (String) c));
    map.put(InternalSampler.PARSER_NAME, (p, c) -> ParsedSampler.fromXContent(p, (String) c));
    map.put(GeoHashGridAggregationBuilder.NAME, (p, c) -> ParsedGeoHashGrid.fromXContent(p, (String) c));
    map.put(GeoTileGridAggregationBuilder.NAME, (p, c) -> ParsedGeoTileGrid.fromXContent(p, (String) c));
    map.put(RangeAggregationBuilder.NAME, (p, c) -> ParsedRange.fromXContent(p, (String) c));
    map.put(DateRangeAggregationBuilder.NAME, (p, c) -> ParsedDateRange.fromXContent(p, (String) c));
    map.put(GeoDistanceAggregationBuilder.NAME, (p, c) -> ParsedGeoDistance.fromXContent(p, (String) c));
    map.put(FiltersAggregationBuilder.NAME, (p, c) -> ParsedFilters.fromXContent(p, (String) c));
    map.put(AdjacencyMatrixAggregationBuilder.NAME, (p, c) -> ParsedAdjacencyMatrix.fromXContent(p, (String) c));
    map.put(SignificantLongTerms.NAME, (p, c) -> ParsedSignificantLongTerms.fromXContent(p, (String) c));
    map.put(SignificantStringTerms.NAME, (p, c) -> ParsedSignificantStringTerms.fromXContent(p, (String) c));
    map.put(ScriptedMetricAggregationBuilder.NAME, (p, c) -> ParsedScriptedMetric.fromXContent(p, (String) c));
    map.put(IpRangeAggregationBuilder.NAME, (p, c) -> ParsedBinaryRange.fromXContent(p, (String) c));
    map.put(TopHitsAggregationBuilder.NAME, (p, c) -> ParsedTopHits.fromXContent(p, (String) c));
    map.put(CompositeAggregationBuilder.NAME, (p, c) -> ParsedComposite.fromXContent(p, (String) c));
    map.put(MultiTermsAggregationBuilder.NAME, (p, c) -> ParsedMultiTerms.fromXContent(p, (String) c));
    List<NamedXContentRegistry.Entry> entries = map.entrySet().stream().map(entry -> new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(entry.getKey()), entry.getValue())).collect(Collectors.toList());
    entries.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField(TermSuggestionBuilder.SUGGESTION_NAME), (parser, context) -> TermSuggestion.fromXContent(parser, (String) context)));
    entries.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField(PhraseSuggestionBuilder.SUGGESTION_NAME), (parser, context) -> PhraseSuggestion.fromXContent(parser, (String) context)));
    entries.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField(CompletionSuggestionBuilder.SUGGESTION_NAME), (parser, context) -> CompletionSuggestion.fromXContent(parser, (String) context)));
    return entries;
}
Also used : Aggregation(org.opensearch.search.aggregations.Aggregation) ActionRequest(org.opensearch.action.ActionRequest) ParsedDateHistogram(org.opensearch.search.aggregations.bucket.histogram.ParsedDateHistogram) ParsedGlobal(org.opensearch.search.aggregations.bucket.global.ParsedGlobal) 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) FilterAggregationBuilder(org.opensearch.search.aggregations.bucket.filter.FilterAggregationBuilder) LongRareTerms(org.opensearch.search.aggregations.bucket.terms.LongRareTerms) LongTerms(org.opensearch.search.aggregations.bucket.terms.LongTerms) VariableWidthHistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.VariableWidthHistogramAggregationBuilder) DerivativePipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder) InternalTDigestPercentileRanks(org.opensearch.search.aggregations.metrics.InternalTDigestPercentileRanks) CompletionSuggestion(org.opensearch.search.suggest.completion.CompletionSuggestion) ParsedValueCount(org.opensearch.search.aggregations.metrics.ParsedValueCount) BytesRestResponse(org.opensearch.rest.BytesRestResponse) Stream(java.util.stream.Stream) XContentType(org.opensearch.common.xcontent.XContentType) ParsedNested(org.opensearch.search.aggregations.bucket.nested.ParsedNested) ParsedAdjacencyMatrix(org.opensearch.search.aggregations.bucket.adjacency.ParsedAdjacencyMatrix) GetSourceRequest(org.opensearch.client.core.GetSourceRequest) ParsedTDigestPercentiles(org.opensearch.search.aggregations.metrics.ParsedTDigestPercentiles) UpdateResponse(org.opensearch.action.update.UpdateResponse) DateHistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) SearchTemplateResponse(org.opensearch.script.mustache.SearchTemplateResponse) ParsedReverseNested(org.opensearch.search.aggregations.bucket.nested.ParsedReverseNested) IOException(java.io.IOException) PutStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) MaxAggregationBuilder(org.opensearch.search.aggregations.metrics.MaxAggregationBuilder) ParsedStats(org.opensearch.search.aggregations.metrics.ParsedStats) ParsedStatsBucket(org.opensearch.search.aggregations.pipeline.ParsedStatsBucket) CompletionSuggestionBuilder(org.opensearch.search.suggest.completion.CompletionSuggestionBuilder) OpenSearchStatusException(org.opensearch.OpenSearchStatusException) BulkRequest(org.opensearch.action.bulk.BulkRequest) ParsedGeoCentroid(org.opensearch.search.aggregations.metrics.ParsedGeoCentroid) TaskSubmissionResponse(org.opensearch.client.tasks.TaskSubmissionResponse) XContentParser(org.opensearch.common.xcontent.XContentParser) ParsedAvg(org.opensearch.search.aggregations.metrics.ParsedAvg) DateRangeAggregationBuilder(org.opensearch.search.aggregations.bucket.range.DateRangeAggregationBuilder) GetResponse(org.opensearch.action.get.GetResponse) InternalTDigestPercentiles(org.opensearch.search.aggregations.metrics.InternalTDigestPercentiles) ParsedSampler(org.opensearch.search.aggregations.bucket.sampler.ParsedSampler) NamedXContentProvider(org.opensearch.plugins.spi.NamedXContentProvider) ParsedComposite(org.opensearch.search.aggregations.bucket.composite.ParsedComposite) HttpEntity(org.apache.http.HttpEntity) ContextParser(org.opensearch.common.xcontent.ContextParser) ParsedMultiTerms(org.opensearch.search.aggregations.bucket.terms.ParsedMultiTerms) ServiceLoader(java.util.ServiceLoader) FiltersAggregationBuilder(org.opensearch.search.aggregations.bucket.filter.FiltersAggregationBuilder) RestStatus(org.opensearch.rest.RestStatus) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TopHitsAggregationBuilder(org.opensearch.search.aggregations.metrics.TopHitsAggregationBuilder) GetStoredScriptResponse(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptResponse) ParsedRange(org.opensearch.search.aggregations.bucket.range.ParsedRange) InternalSimpleValue(org.opensearch.search.aggregations.pipeline.InternalSimpleValue) ParsedCardinality(org.opensearch.search.aggregations.metrics.ParsedCardinality) CheckedConsumer(org.opensearch.common.CheckedConsumer) Function(java.util.function.Function) AutoDateHistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.AutoDateHistogramAggregationBuilder) ParsedHistogram(org.opensearch.search.aggregations.bucket.histogram.ParsedHistogram) ParsedGeoDistance(org.opensearch.search.aggregations.bucket.range.ParsedGeoDistance) CompositeAggregationBuilder(org.opensearch.search.aggregations.bucket.composite.CompositeAggregationBuilder) ListTasksResponse(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse) ParsedSignificantStringTerms(org.opensearch.search.aggregations.bucket.terms.ParsedSignificantStringTerms) ClearScrollResponse(org.opensearch.action.search.ClearScrollResponse) ParsedGeoBounds(org.opensearch.search.aggregations.metrics.ParsedGeoBounds) SearchResponse(org.opensearch.action.search.SearchResponse) SignificantStringTerms(org.opensearch.search.aggregations.bucket.terms.SignificantStringTerms) GeoTileGridAggregationBuilder(org.opensearch.search.aggregations.bucket.geogrid.GeoTileGridAggregationBuilder) DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) AdjacencyMatrixAggregationBuilder(org.opensearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder) ParsedHDRPercentileRanks(org.opensearch.search.aggregations.metrics.ParsedHDRPercentileRanks) MultiTermsAggregationBuilder(org.opensearch.search.aggregations.bucket.terms.MultiTermsAggregationBuilder) BulkByScrollResponse(org.opensearch.index.reindex.BulkByScrollResponse) SignificantLongTerms(org.opensearch.search.aggregations.bucket.terms.SignificantLongTerms) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) Collectors.toList(java.util.stream.Collectors.toList) StatsBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.StatsBucketPipelineAggregationBuilder) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) ReindexRequest(org.opensearch.index.reindex.ReindexRequest) ParsedMissing(org.opensearch.search.aggregations.bucket.missing.ParsedMissing) ExtendedStatsBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregationBuilder) InternalSampler(org.opensearch.search.aggregations.bucket.sampler.InternalSampler) MainResponse(org.opensearch.client.core.MainResponse) ParsedMax(org.opensearch.search.aggregations.metrics.ParsedMax) CheckedFunction(org.opensearch.common.CheckedFunction) ParsedDateRange(org.opensearch.search.aggregations.bucket.range.ParsedDateRange) IndexResponse(org.opensearch.action.index.IndexResponse) 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) IpRangeAggregationBuilder(org.opensearch.search.aggregations.bucket.range.IpRangeAggregationBuilder) StringRareTerms(org.opensearch.search.aggregations.bucket.terms.StringRareTerms) ActionListener(org.opensearch.action.ActionListener) InternalHDRPercentiles(org.opensearch.search.aggregations.metrics.InternalHDRPercentiles) TermSuggestionBuilder(org.opensearch.search.suggest.term.TermSuggestionBuilder) DeleteRequest(org.opensearch.action.delete.DeleteRequest) ParsedSimpleValue(org.opensearch.search.aggregations.pipeline.ParsedSimpleValue) TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) ParsedHDRPercentiles(org.opensearch.search.aggregations.metrics.ParsedHDRPercentiles) MultiTermVectorsResponse(org.opensearch.client.core.MultiTermVectorsResponse) RankEvalResponse(org.opensearch.index.rankeval.RankEvalResponse) GlobalAggregationBuilder(org.opensearch.search.aggregations.bucket.global.GlobalAggregationBuilder) Set(java.util.Set) PhraseSuggestion(org.opensearch.search.suggest.phrase.PhraseSuggestion) MultiSearchResponse(org.opensearch.action.search.MultiSearchResponse) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest) CardinalityAggregationBuilder(org.opensearch.search.aggregations.metrics.CardinalityAggregationBuilder) GeoHashGridAggregationBuilder(org.opensearch.search.aggregations.bucket.geogrid.GeoHashGridAggregationBuilder) ParsedGeoTileGrid(org.opensearch.search.aggregations.bucket.geogrid.ParsedGeoTileGrid) ValueCountAggregationBuilder(org.opensearch.search.aggregations.metrics.ValueCountAggregationBuilder) UpdateRequest(org.opensearch.action.update.UpdateRequest) MinAggregationBuilder(org.opensearch.search.aggregations.metrics.MinAggregationBuilder) ParsedDerivative(org.opensearch.search.aggregations.pipeline.ParsedDerivative) ReverseNestedAggregationBuilder(org.opensearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder) MissingAggregationBuilder(org.opensearch.search.aggregations.bucket.missing.MissingAggregationBuilder) TermSuggestion(org.opensearch.search.suggest.term.TermSuggestion) MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) StringTerms(org.opensearch.search.aggregations.bucket.terms.StringTerms) ParseField(org.opensearch.common.ParseField) ArrayList(java.util.ArrayList) TermVectorsResponse(org.opensearch.client.core.TermVectorsResponse) DeleteResponse(org.opensearch.action.delete.DeleteResponse) ExplainRequest(org.opensearch.action.explain.ExplainRequest) SearchRequest(org.opensearch.action.search.SearchRequest) MainRequest(org.opensearch.client.core.MainRequest) MultiSearchTemplateResponse(org.opensearch.script.mustache.MultiSearchTemplateResponse) ParsedWeightedAvg(org.opensearch.search.aggregations.metrics.ParsedWeightedAvg) ParsedExtendedStats(org.opensearch.search.aggregations.metrics.ParsedExtendedStats) PhraseSuggestionBuilder(org.opensearch.search.suggest.phrase.PhraseSuggestionBuilder) StatsAggregationBuilder(org.opensearch.search.aggregations.metrics.StatsAggregationBuilder) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) DeleteByQueryRequest(org.opensearch.index.reindex.DeleteByQueryRequest) ParsedScriptedMetric(org.opensearch.search.aggregations.metrics.ParsedScriptedMetric) SumAggregationBuilder(org.opensearch.search.aggregations.metrics.SumAggregationBuilder) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) MultiGetResponse(org.opensearch.action.get.MultiGetResponse) Aggregation(org.opensearch.search.aggregations.Aggregation) RangeAggregationBuilder(org.opensearch.search.aggregations.bucket.range.RangeAggregationBuilder) ParsedStringTerms(org.opensearch.search.aggregations.bucket.terms.ParsedStringTerms) OpenSearchException(org.opensearch.OpenSearchException) ExtendedStatsAggregationBuilder(org.opensearch.search.aggregations.metrics.ExtendedStatsAggregationBuilder) ScriptedMetricAggregationBuilder(org.opensearch.search.aggregations.metrics.ScriptedMetricAggregationBuilder) ParsedTDigestPercentileRanks(org.opensearch.search.aggregations.metrics.ParsedTDigestPercentileRanks) Collections.singleton(java.util.Collections.singleton) GetStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) MedianAbsoluteDeviationAggregationBuilder(org.opensearch.search.aggregations.metrics.MedianAbsoluteDeviationAggregationBuilder) ParsedFilter(org.opensearch.search.aggregations.bucket.filter.ParsedFilter) ParsedFilters(org.opensearch.search.aggregations.bucket.filter.ParsedFilters) CountRequest(org.opensearch.client.core.CountRequest) ParsedVariableWidthHistogram(org.opensearch.search.aggregations.bucket.histogram.ParsedVariableWidthHistogram) WeightedAvgAggregationBuilder(org.opensearch.search.aggregations.metrics.WeightedAvgAggregationBuilder) InternalHDRPercentileRanks(org.opensearch.search.aggregations.metrics.InternalHDRPercentileRanks) List(java.util.List) CountResponse(org.opensearch.client.core.CountResponse) ParsedBinaryRange(org.opensearch.search.aggregations.bucket.range.ParsedBinaryRange) PercentilesBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.PercentilesBucketPipelineAggregationBuilder) Optional(java.util.Optional) SearchTemplateRequest(org.opensearch.script.mustache.SearchTemplateRequest) RankEvalRequest(org.opensearch.index.rankeval.RankEvalRequest) ParsedTopHits(org.opensearch.search.aggregations.metrics.ParsedTopHits) DoubleTerms(org.opensearch.search.aggregations.bucket.terms.DoubleTerms) GetSourceResponse(org.opensearch.client.core.GetSourceResponse) ParsedPercentilesBucket(org.opensearch.search.aggregations.pipeline.ParsedPercentilesBucket) HistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder) AvgAggregationBuilder(org.opensearch.search.aggregations.metrics.AvgAggregationBuilder) ParsedAutoDateHistogram(org.opensearch.search.aggregations.bucket.histogram.ParsedAutoDateHistogram) HashMap(java.util.HashMap) ActionRequestValidationException(org.opensearch.action.ActionRequestValidationException) GeoCentroidAggregationBuilder(org.opensearch.search.aggregations.metrics.GeoCentroidAggregationBuilder) ParsedExtendedStatsBucket(org.opensearch.search.aggregations.pipeline.ParsedExtendedStatsBucket) ParsedLongRareTerms(org.opensearch.search.aggregations.bucket.terms.ParsedLongRareTerms) ParsedMedianAbsoluteDeviation(org.opensearch.search.aggregations.metrics.ParsedMedianAbsoluteDeviation) ParsedLongTerms(org.opensearch.search.aggregations.bucket.terms.ParsedLongTerms) ParsedDoubleTerms(org.opensearch.search.aggregations.bucket.terms.ParsedDoubleTerms) ExplainResponse(org.opensearch.action.explain.ExplainResponse) Collections.emptySet(java.util.Collections.emptySet) GetRequest(org.opensearch.action.get.GetRequest) MultiSearchTemplateRequest(org.opensearch.script.mustache.MultiSearchTemplateRequest) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) ParsedGeoHashGrid(org.opensearch.search.aggregations.bucket.geogrid.ParsedGeoHashGrid) BulkResponse(org.opensearch.action.bulk.BulkResponse) Suggest(org.opensearch.search.suggest.Suggest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) Closeable(java.io.Closeable) InternalBucketMetricValue(org.opensearch.search.aggregations.pipeline.InternalBucketMetricValue) IndexRequest(org.opensearch.action.index.IndexRequest) NestedAggregationBuilder(org.opensearch.search.aggregations.bucket.nested.NestedAggregationBuilder) DeprecationHandler(org.opensearch.common.xcontent.DeprecationHandler) Collections(java.util.Collections) CompletionSuggestion(org.opensearch.search.suggest.completion.CompletionSuggestion) PhraseSuggestion(org.opensearch.search.suggest.phrase.PhraseSuggestion) TermSuggestion(org.opensearch.search.suggest.term.TermSuggestion) ContextParser(org.opensearch.common.xcontent.ContextParser) HashMap(java.util.HashMap) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ParseField(org.opensearch.common.ParseField)

Example 28 with Aggregation

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

the class ParentIT method testParentAggs.

public void testParentAggs() throws Exception {
    final SearchRequestBuilder searchRequest = client().prepareSearch("test").setSize(10000).setQuery(matchQuery("randomized", true)).addAggregation(terms("to_commenter").field("commenter").size(10000).subAggregation(parent("to_article", "comment").subAggregation(terms("to_category").field("category").size(10000).subAggregation(topHits("top_category")))));
    SearchResponse searchResponse = searchRequest.get();
    assertSearchResponse(searchResponse);
    final Set<String> commenters = getCommenters();
    final Map<String, Set<String>> commenterToComments = getCommenterToComments();
    Terms categoryTerms = searchResponse.getAggregations().get("to_commenter");
    assertThat("Request: " + searchRequest + "\nResponse: " + searchResponse + "\n", categoryTerms.getBuckets().size(), equalTo(commenters.size()));
    for (Terms.Bucket commenterBucket : categoryTerms.getBuckets()) {
        Set<String> comments = commenterToComments.get(commenterBucket.getKeyAsString());
        assertNotNull(comments);
        assertThat("Failed for commenter " + commenterBucket.getKeyAsString(), commenterBucket.getDocCount(), equalTo((long) comments.size()));
        Parent articleAgg = commenterBucket.getAggregations().get("to_article");
        assertThat(articleAgg.getName(), equalTo("to_article"));
        // find all articles for the comments for the current commenter
        Set<String> articles = articleToControl.values().stream().flatMap((Function<ParentControl, Stream<String>>) parentControl -> parentControl.commentIds.stream().filter(comments::contains)).collect(Collectors.toSet());
        assertThat(articleAgg.getDocCount(), equalTo((long) articles.size()));
        Terms categoryAgg = articleAgg.getAggregations().get("to_category");
        assertNotNull(categoryAgg);
        List<String> categories = categoryToControl.entrySet().stream().filter(entry -> entry.getValue().commenterToCommentId.containsKey(commenterBucket.getKeyAsString())).map(Map.Entry::getKey).collect(Collectors.toList());
        for (String category : categories) {
            Terms.Bucket categoryBucket = categoryAgg.getBucketByKey(category);
            assertNotNull(categoryBucket);
            Aggregation topCategory = categoryBucket.getAggregations().get("top_category");
            assertNotNull(topCategory);
        }
    }
    for (String commenter : commenters) {
        Terms.Bucket categoryBucket = categoryTerms.getBucketByKey(commenter);
        assertThat(categoryBucket.getKeyAsString(), equalTo(commenter));
        assertThat(categoryBucket.getDocCount(), equalTo((long) commenterToComments.get(commenter).size()));
        Parent childrenBucket = categoryBucket.getAggregations().get("to_article");
        assertThat(childrenBucket.getName(), equalTo("to_article"));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SearchRequestBuilder(org.opensearch.action.search.SearchRequestBuilder) Terms(org.opensearch.search.aggregations.bucket.terms.Terms) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse) Aggregation(org.opensearch.search.aggregations.Aggregation) MultiBucketsAggregation(org.opensearch.search.aggregations.bucket.MultiBucketsAggregation) Function(java.util.function.Function) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with Aggregation

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

the class DateRangeAggregatorTests method testKeywordField.

public void testKeywordField() {
    DateRangeAggregationBuilder aggregationBuilder = new DateRangeAggregationBuilder("date_range").field("not_a_number").addRange("2015-11-13", "2015-11-14");
    MappedFieldType fieldType = new KeywordFieldMapper.KeywordFieldType("not_a_number");
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> testCase(aggregationBuilder, new MatchAllDocsQuery(), iw -> {
        iw.addDocument(singleton(new SortedSetDocValuesField("string", new BytesRef("foo"))));
    }, range -> fail("Should have thrown exception"), fieldType));
    assertEquals("Field [not_a_number] of type [keyword] is not supported for aggregation [date_range]", e.getMessage());
}
Also used : Query(org.apache.lucene.search.Query) Aggregation(org.opensearch.search.aggregations.Aggregation) ZonedDateTime(java.time.ZonedDateTime) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) CheckedConsumer(org.opensearch.common.CheckedConsumer) NumberFieldMapper(org.opensearch.index.mapper.NumberFieldMapper) Collections.singleton(java.util.Collections.singleton) Directory(org.apache.lucene.store.Directory) ZoneOffset(java.time.ZoneOffset) KeywordFieldMapper(org.opensearch.index.mapper.KeywordFieldMapper) AggregationInspectionHelper(org.opensearch.search.aggregations.support.AggregationInspectionHelper) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) AggregatorTestCase(org.opensearch.search.aggregations.AggregatorTestCase) BytesRef(org.apache.lucene.util.BytesRef) MappedFieldType(org.opensearch.index.mapper.MappedFieldType) DirectoryReader(org.apache.lucene.index.DirectoryReader) OpenSearchParseException(org.opensearch.OpenSearchParseException) IOException(java.io.IOException) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Consumer(java.util.function.Consumer) List(java.util.List) RandomIndexWriter(org.apache.lucene.tests.index.RandomIndexWriter) DateFieldMapper(org.opensearch.index.mapper.DateFieldMapper) MultiBucketConsumerService(org.opensearch.search.aggregations.MultiBucketConsumerService) Collections(java.util.Collections) IndexReader(org.apache.lucene.index.IndexReader) IndexSearcher(org.apache.lucene.search.IndexSearcher) MappedFieldType(org.opensearch.index.mapper.MappedFieldType) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BytesRef(org.apache.lucene.util.BytesRef)

Example 30 with Aggregation

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

the class BucketMetricsPipelineAggregator method doReduce.

@Override
public final InternalAggregation doReduce(Aggregations aggregations, ReduceContext context) {
    preCollection();
    List<String> bucketsPath = AggregationPath.parse(bucketsPaths()[0]).getPathElementsAsStringList();
    for (Aggregation aggregation : aggregations) {
        if (aggregation.getName().equals(bucketsPath.get(0))) {
            List<String> sublistedPath = bucketsPath.subList(1, bucketsPath.size());
            InternalMultiBucketAggregation<?, ?> multiBucketsAgg = (InternalMultiBucketAggregation<?, ?>) aggregation;
            List<? extends InternalMultiBucketAggregation.InternalBucket> buckets = multiBucketsAgg.getBuckets();
            for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) {
                Double bucketValue = BucketHelpers.resolveBucketValue(multiBucketsAgg, bucket, sublistedPath, gapPolicy);
                if (bucketValue != null && !Double.isNaN(bucketValue)) {
                    collectBucketValue(bucket.getKeyAsString(), bucketValue);
                }
            }
        }
    }
    return buildAggregation(metadata());
}
Also used : Aggregation(org.opensearch.search.aggregations.Aggregation) InternalMultiBucketAggregation(org.opensearch.search.aggregations.InternalMultiBucketAggregation) InternalAggregation(org.opensearch.search.aggregations.InternalAggregation) InternalMultiBucketAggregation(org.opensearch.search.aggregations.InternalMultiBucketAggregation)

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