Search in sources :

Example 1 with DerivativePipelineAggregationBuilder

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

the class SearchModuleTests method testDoubleRegister.

public void testDoubleRegister() {
    SearchPlugin registersDupeHighlighter = new SearchPlugin() {

        @Override
        public Map<String, Highlighter> getHighlighters() {
            return singletonMap("plain", new PlainHighlighter());
        }
    };
    expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeHighlighter));
    SearchPlugin registersDupeSuggester = new SearchPlugin() {

        @Override
        public List<SearchPlugin.SuggesterSpec<?>> getSuggesters() {
            return singletonList(new SuggesterSpec<>(TermSuggestionBuilder.SUGGESTION_NAME, TermSuggestionBuilder::new, TermSuggestionBuilder::fromXContent, TermSuggestion::new));
        }
    };
    expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeSuggester));
    SearchPlugin registersDupeScoreFunction = new SearchPlugin() {

        @Override
        public List<ScoreFunctionSpec<?>> getScoreFunctions() {
            return singletonList(new ScoreFunctionSpec<>(GaussDecayFunctionBuilder.NAME, GaussDecayFunctionBuilder::new, GaussDecayFunctionBuilder.PARSER));
        }
    };
    expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeScoreFunction));
    SearchPlugin registersDupeSignificanceHeuristic = new SearchPlugin() {

        @Override
        public List<SignificanceHeuristicSpec<?>> getSignificanceHeuristics() {
            return singletonList(new SignificanceHeuristicSpec<>(ChiSquare.NAME, ChiSquare::new, ChiSquare.PARSER));
        }
    };
    expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeSignificanceHeuristic));
    SearchPlugin registersDupeMovAvgModel = new SearchPlugin() {

        @Override
        public List<SearchExtensionSpec<MovAvgModel, MovAvgModel.AbstractModelParser>> getMovingAverageModels() {
            return singletonList(new SearchExtensionSpec<>(SimpleModel.NAME, SimpleModel::new, SimpleModel.PARSER));
        }
    };
    expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeMovAvgModel));
    SearchPlugin registersDupeFetchSubPhase = new SearchPlugin() {

        @Override
        public List<FetchSubPhase> getFetchSubPhases(FetchPhaseConstructionContext context) {
            return singletonList(new ExplainPhase());
        }
    };
    expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeFetchSubPhase));
    SearchPlugin registersDupeQuery = new SearchPlugin() {

        @Override
        public List<SearchPlugin.QuerySpec<?>> getQueries() {
            return singletonList(new QuerySpec<>(TermQueryBuilder.NAME, TermQueryBuilder::new, TermQueryBuilder::fromXContent));
        }
    };
    expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeQuery));
    SearchPlugin registersDupeAggregation = new SearchPlugin() {

        @Override
        public List<AggregationSpec> getAggregations() {
            return singletonList(new AggregationSpec(TermsAggregationBuilder.NAME, TermsAggregationBuilder::new, TermsAggregationBuilder.PARSER));
        }
    };
    expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeAggregation));
    SearchPlugin registersDupePipelineAggregation = new SearchPlugin() {

        @Override
        public List<PipelineAggregationSpec> getPipelineAggregations() {
            return singletonList(new PipelineAggregationSpec(DerivativePipelineAggregationBuilder.NAME, DerivativePipelineAggregationBuilder::new, DerivativePipelineAggregator::new, DerivativePipelineAggregationBuilder::parse).addResultReader(InternalDerivative::new));
        }
    };
    expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupePipelineAggregation));
    SearchPlugin registersDupeRescorer = new SearchPlugin() {

        @Override
        public List<RescorerSpec<?>> getRescorers() {
            return singletonList(new RescorerSpec<>(QueryRescorerBuilder.NAME, QueryRescorerBuilder::new, QueryRescorerBuilder::fromXContent));
        }
    };
    expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeRescorer));
}
Also used : MovAvgModel(org.opensearch.search.aggregations.pipeline.MovAvgModel) ExplainPhase(org.opensearch.search.fetch.subphase.ExplainPhase) SearchPlugin(org.opensearch.plugins.SearchPlugin) DerivativePipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder) PlainHighlighter(org.opensearch.search.fetch.subphase.highlight.PlainHighlighter) DerivativePipelineAggregator(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregator) FetchSubPhase(org.opensearch.search.fetch.FetchSubPhase) UnifiedHighlighter(org.opensearch.search.fetch.subphase.highlight.UnifiedHighlighter) Highlighter(org.opensearch.search.fetch.subphase.highlight.Highlighter) FastVectorHighlighter(org.opensearch.search.fetch.subphase.highlight.FastVectorHighlighter) PlainHighlighter(org.opensearch.search.fetch.subphase.highlight.PlainHighlighter) CustomHighlighter(org.opensearch.search.fetch.subphase.highlight.CustomHighlighter)

Example 2 with DerivativePipelineAggregationBuilder

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

the class CCSDuelIT method testPipelineAggs.

public void testPipelineAggs() throws Exception {
    assumeMultiClusterSetup();
    SearchRequest searchRequest = initSearchRequest();
    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.query(new TermQueryBuilder("type", "answer"));
    searchRequest.source(sourceBuilder);
    sourceBuilder.size(0);
    DateHistogramAggregationBuilder daily = new DateHistogramAggregationBuilder("daily");
    daily.field("creationDate");
    daily.calendarInterval(DateHistogramInterval.DAY);
    sourceBuilder.aggregation(daily);
    daily.subAggregation(new DerivativePipelineAggregationBuilder("derivative", "_count"));
    sourceBuilder.aggregation(new MaxBucketPipelineAggregationBuilder("biggest_day", "daily._count"));
    daily.subAggregation(new SumAggregationBuilder("votes").field("votes"));
    sourceBuilder.aggregation(new MaxBucketPipelineAggregationBuilder("most_voted", "daily>votes"));
    duelSearch(searchRequest, response -> {
        assertAggs(response);
        assertNotNull(response.getAggregations().get("most_voted"));
    });
    duelSearch(searchRequest, CCSDuelIT::assertAggs);
}
Also used : SumAggregationBuilder(org.opensearch.search.aggregations.metrics.SumAggregationBuilder) SearchRequest(org.opensearch.action.search.SearchRequest) MaxBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.MaxBucketPipelineAggregationBuilder) DerivativePipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder) DateHistogramAggregationBuilder(org.opensearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder)

Example 3 with DerivativePipelineAggregationBuilder

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

the class SearchModule method registerPipelineAggregations.

private void registerPipelineAggregations(List<SearchPlugin> plugins) {
    registerPipelineAggregation(new PipelineAggregationSpec(DerivativePipelineAggregationBuilder.NAME, DerivativePipelineAggregationBuilder::new, DerivativePipelineAggregator::new, DerivativePipelineAggregationBuilder::parse).addResultReader(InternalDerivative::new));
    registerPipelineAggregation(new PipelineAggregationSpec(MaxBucketPipelineAggregationBuilder.NAME, MaxBucketPipelineAggregationBuilder::new, MaxBucketPipelineAggregator::new, MaxBucketPipelineAggregationBuilder.PARSER).addResultReader(InternalBucketMetricValue.NAME, InternalBucketMetricValue::new));
    registerPipelineAggregation(new PipelineAggregationSpec(MinBucketPipelineAggregationBuilder.NAME, MinBucketPipelineAggregationBuilder::new, MinBucketPipelineAggregator::new, MinBucketPipelineAggregationBuilder.PARSER));
    registerPipelineAggregation(new PipelineAggregationSpec(AvgBucketPipelineAggregationBuilder.NAME, AvgBucketPipelineAggregationBuilder::new, AvgBucketPipelineAggregator::new, AvgBucketPipelineAggregationBuilder.PARSER).addResultReader(InternalSimpleValue.NAME, InternalSimpleValue::new));
    registerPipelineAggregation(new PipelineAggregationSpec(SumBucketPipelineAggregationBuilder.NAME, SumBucketPipelineAggregationBuilder::new, SumBucketPipelineAggregator::new, SumBucketPipelineAggregationBuilder.PARSER));
    registerPipelineAggregation(new PipelineAggregationSpec(StatsBucketPipelineAggregationBuilder.NAME, StatsBucketPipelineAggregationBuilder::new, StatsBucketPipelineAggregator::new, StatsBucketPipelineAggregationBuilder.PARSER).addResultReader(InternalStatsBucket::new));
    registerPipelineAggregation(new PipelineAggregationSpec(ExtendedStatsBucketPipelineAggregationBuilder.NAME, ExtendedStatsBucketPipelineAggregationBuilder::new, ExtendedStatsBucketPipelineAggregator::new, new ExtendedStatsBucketParser()).addResultReader(InternalExtendedStatsBucket::new));
    registerPipelineAggregation(new PipelineAggregationSpec(PercentilesBucketPipelineAggregationBuilder.NAME, PercentilesBucketPipelineAggregationBuilder::new, PercentilesBucketPipelineAggregator::new, PercentilesBucketPipelineAggregationBuilder.PARSER).addResultReader(InternalPercentilesBucket::new));
    registerPipelineAggregation(new PipelineAggregationSpec(MovAvgPipelineAggregationBuilder.NAME, MovAvgPipelineAggregationBuilder::new, MovAvgPipelineAggregator::new, (XContentParser parser, String name) -> MovAvgPipelineAggregationBuilder.parse(movingAverageModelParserRegistry, name, parser)));
    registerPipelineAggregation(new PipelineAggregationSpec(CumulativeSumPipelineAggregationBuilder.NAME, CumulativeSumPipelineAggregationBuilder::new, CumulativeSumPipelineAggregator::new, CumulativeSumPipelineAggregationBuilder.PARSER));
    registerPipelineAggregation(new PipelineAggregationSpec(BucketScriptPipelineAggregationBuilder.NAME, BucketScriptPipelineAggregationBuilder::new, BucketScriptPipelineAggregator::new, BucketScriptPipelineAggregationBuilder.PARSER));
    registerPipelineAggregation(new PipelineAggregationSpec(BucketSelectorPipelineAggregationBuilder.NAME, BucketSelectorPipelineAggregationBuilder::new, BucketSelectorPipelineAggregator::new, BucketSelectorPipelineAggregationBuilder::parse));
    registerPipelineAggregation(new PipelineAggregationSpec(BucketSortPipelineAggregationBuilder.NAME, BucketSortPipelineAggregationBuilder::new, BucketSortPipelineAggregator::new, BucketSortPipelineAggregationBuilder::parse));
    registerPipelineAggregation(new PipelineAggregationSpec(SerialDiffPipelineAggregationBuilder.NAME, SerialDiffPipelineAggregationBuilder::new, SerialDiffPipelineAggregator::new, SerialDiffPipelineAggregationBuilder::parse));
    registerPipelineAggregation(new PipelineAggregationSpec(MovFnPipelineAggregationBuilder.NAME, MovFnPipelineAggregationBuilder::new, MovFnPipelineAggregator::new, MovFnPipelineAggregationBuilder.PARSER));
    registerFromPlugin(plugins, SearchPlugin::getPipelineAggregations, this::registerPipelineAggregation);
}
Also used : MaxBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.MaxBucketPipelineAggregationBuilder) ExtendedStatsBucketPipelineAggregator(org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregator) PercentilesBucketPipelineAggregator(org.opensearch.search.aggregations.pipeline.PercentilesBucketPipelineAggregator) StatsBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.StatsBucketPipelineAggregationBuilder) ExtendedStatsBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregationBuilder) PercentilesBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.PercentilesBucketPipelineAggregationBuilder) SearchPlugin(org.opensearch.plugins.SearchPlugin) PipelineAggregationSpec(org.opensearch.plugins.SearchPlugin.PipelineAggregationSpec) DerivativePipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder) ExtendedStatsBucketParser(org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketParser) DerivativePipelineAggregator(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregator) ExtendedStatsBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregationBuilder) AvgBucketPipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.AvgBucketPipelineAggregationBuilder) MaxBucketPipelineAggregator(org.opensearch.search.aggregations.pipeline.MaxBucketPipelineAggregator) AvgBucketPipelineAggregator(org.opensearch.search.aggregations.pipeline.AvgBucketPipelineAggregator) XContentParser(org.opensearch.common.xcontent.XContentParser) ExtendedStatsBucketPipelineAggregator(org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregator) StatsBucketPipelineAggregator(org.opensearch.search.aggregations.pipeline.StatsBucketPipelineAggregator)

Example 4 with DerivativePipelineAggregationBuilder

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

the class AutoDateHistogramAggregatorTests method testWithPipelineReductions.

public void testWithPipelineReductions() throws IOException {
    testSearchCase(DEFAULT_QUERY, DATES_WITH_TIME, aggregation -> aggregation.setNumBuckets(1).field(DATE_FIELD).subAggregation(AggregationBuilders.histogram("histo").field(NUMERIC_FIELD).interval(1).subAggregation(AggregationBuilders.max("max").field(NUMERIC_FIELD)).subAggregation(new DerivativePipelineAggregationBuilder("deriv", "max"))), histogram -> {
        assertTrue(AggregationInspectionHelper.hasValue(histogram));
        final List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
        assertEquals(1, buckets.size());
        Histogram.Bucket bucket = buckets.get(0);
        assertEquals("2010-01-01T00:00:00.000Z", bucket.getKeyAsString());
        assertEquals(10, bucket.getDocCount());
        assertThat(bucket.getAggregations().asList().size(), equalTo(1));
        InternalHistogram histo = (InternalHistogram) bucket.getAggregations().asList().get(0);
        assertThat(histo.getBuckets().size(), equalTo(10));
        for (int i = 0; i < 10; i++) {
            assertThat(histo.getBuckets().get(i).key, equalTo((double) i));
            assertThat(((InternalMax) histo.getBuckets().get(i).aggregations.get("max")).getValue(), equalTo((double) i));
            if (i > 0) {
                assertThat(((InternalSimpleValue) histo.getBuckets().get(i).aggregations.get("deriv")).getValue(), equalTo(1.0));
            }
        }
    });
}
Also used : DerivativePipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder) LongPoint(org.apache.lucene.document.LongPoint)

Aggregations

DerivativePipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder)4 SearchPlugin (org.opensearch.plugins.SearchPlugin)2 DerivativePipelineAggregator (org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregator)2 MaxBucketPipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.MaxBucketPipelineAggregationBuilder)2 LongPoint (org.apache.lucene.document.LongPoint)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 XContentParser (org.opensearch.common.xcontent.XContentParser)1 TermQueryBuilder (org.opensearch.index.query.TermQueryBuilder)1 PipelineAggregationSpec (org.opensearch.plugins.SearchPlugin.PipelineAggregationSpec)1 DateHistogramAggregationBuilder (org.opensearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder)1 SumAggregationBuilder (org.opensearch.search.aggregations.metrics.SumAggregationBuilder)1 AvgBucketPipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.AvgBucketPipelineAggregationBuilder)1 AvgBucketPipelineAggregator (org.opensearch.search.aggregations.pipeline.AvgBucketPipelineAggregator)1 ExtendedStatsBucketParser (org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketParser)1 ExtendedStatsBucketPipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregationBuilder)1 ExtendedStatsBucketPipelineAggregator (org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregator)1 MaxBucketPipelineAggregator (org.opensearch.search.aggregations.pipeline.MaxBucketPipelineAggregator)1 MovAvgModel (org.opensearch.search.aggregations.pipeline.MovAvgModel)1 PercentilesBucketPipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.PercentilesBucketPipelineAggregationBuilder)1 PercentilesBucketPipelineAggregator (org.opensearch.search.aggregations.pipeline.PercentilesBucketPipelineAggregator)1