Search in sources :

Example 21 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class HighlightBuilderTests method testParsingTagsSchema.

/**
     * `tags_schema` is not produced by toXContent in the builder but should be parseable, so this
     * adds a simple json test for this.
     */
public void testParsingTagsSchema() throws IOException {
    String highlightElement = "{\n" + "    \"tags_schema\" : \"styled\"\n" + "}\n";
    XContentParser parser = createParser(JsonXContent.jsonXContent, highlightElement);
    QueryParseContext context = new QueryParseContext(parser);
    HighlightBuilder highlightBuilder = HighlightBuilder.fromXContent(context);
    assertArrayEquals("setting tags_schema 'styled' should alter pre_tags", HighlightBuilder.DEFAULT_STYLED_PRE_TAG, highlightBuilder.preTags());
    assertArrayEquals("setting tags_schema 'styled' should alter post_tags", HighlightBuilder.DEFAULT_STYLED_POST_TAGS, highlightBuilder.postTags());
    highlightElement = "{\n" + "    \"tags_schema\" : \"default\"\n" + "}\n";
    parser = createParser(JsonXContent.jsonXContent, highlightElement);
    context = new QueryParseContext(parser);
    highlightBuilder = HighlightBuilder.fromXContent(context);
    assertArrayEquals("setting tags_schema 'default' should alter pre_tags", HighlightBuilder.DEFAULT_PRE_TAGS, highlightBuilder.preTags());
    assertArrayEquals("setting tags_schema 'default' should alter post_tags", HighlightBuilder.DEFAULT_POST_TAGS, highlightBuilder.postTags());
    ParsingException e = expectParseThrows(ParsingException.class, "{\n" + "    \"tags_schema\" : \"somthing_else\"\n" + "}\n");
    assertEquals("[highlight] failed to parse field [tags_schema]", e.getMessage());
    assertEquals("Unknown tag schema [somthing_else]", e.getCause().getMessage());
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) ParsingException(org.elasticsearch.common.ParsingException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 22 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class AbstractSortTestCase method testFromXContent.

/**
     * Test that creates new sort from a random test sort and checks both for equality
     */
public void testFromXContent() throws IOException {
    for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {
        T testItem = createTestItem();
        XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
        if (randomBoolean()) {
            builder.prettyPrint();
        }
        testItem.toXContent(builder, ToXContent.EMPTY_PARAMS);
        XContentBuilder shuffled = shuffleXContent(builder);
        XContentParser itemParser = createParser(shuffled);
        itemParser.nextToken();
        /*
             * filter out name of sort, or field name to sort on for element fieldSort
             */
        itemParser.nextToken();
        String elementName = itemParser.currentName();
        itemParser.nextToken();
        QueryParseContext context = new QueryParseContext(itemParser);
        T parsedItem = fromXContent(context, elementName);
        assertNotSame(testItem, parsedItem);
        assertEquals(testItem, parsedItem);
        assertEquals(testItem.hashCode(), parsedItem.hashCode());
    }
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 23 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class AliasValidator method validateAliasFilter.

private static void validateAliasFilter(XContentParser parser, QueryShardContext queryShardContext) throws IOException {
    QueryParseContext queryParseContext = queryShardContext.newParseContext(parser);
    QueryBuilder parseInnerQueryBuilder = queryParseContext.parseInnerQueryBuilder();
    QueryBuilder queryBuilder = QueryBuilder.rewriteQuery(parseInnerQueryBuilder, queryShardContext);
    queryBuilder.toFilter(queryShardContext);
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Example 24 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class SearchModule method registerQuery.

private void registerQuery(QuerySpec<?> spec) {
    namedWriteables.add(new NamedWriteableRegistry.Entry(QueryBuilder.class, spec.getName().getPreferredName(), spec.getReader()));
    namedXContents.add(new NamedXContentRegistry.Entry(QueryBuilder.class, spec.getName(), (p, c) -> spec.getParser().fromXContent((QueryParseContext) c)));
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) InternalReverseNested(org.elasticsearch.search.aggregations.bucket.nested.InternalReverseNested) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) NestedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder) DerivativePipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregationBuilder) SumBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregationBuilder) UnmappedSampler(org.elasticsearch.search.aggregations.bucket.sampler.UnmappedSampler) RangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder) SumAggregationBuilder(org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder) HasParentQueryBuilder(org.elasticsearch.index.query.HasParentQueryBuilder) LongTerms(org.elasticsearch.search.aggregations.bucket.terms.LongTerms) InternalGeoBounds(org.elasticsearch.search.aggregations.metrics.geobounds.InternalGeoBounds) FieldValueFactorFunctionBuilder(org.elasticsearch.index.query.functionscore.FieldValueFactorFunctionBuilder) Map(java.util.Map) SuggesterSpec(org.elasticsearch.plugins.SearchPlugin.SuggesterSpec) ExtendedStatsBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregationBuilder) InternalExtendedStatsBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.InternalExtendedStatsBucket) SignificanceHeuristicParser(org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser) MutualInformation(org.elasticsearch.search.aggregations.bucket.significant.heuristics.MutualInformation) InternalDerivative(org.elasticsearch.search.aggregations.pipeline.derivative.InternalDerivative) InternalGeoDistance(org.elasticsearch.search.aggregations.bucket.range.geodistance.InternalGeoDistance) NamedRegistry(org.elasticsearch.common.NamedRegistry) ScriptScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder) InternalAggregation(org.elasticsearch.search.aggregations.InternalAggregation) MaxAggregationBuilder(org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder) RandomScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.RandomScoreFunctionBuilder) FastVectorHighlighter(org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter) GeoDistanceQueryBuilder(org.elasticsearch.index.query.GeoDistanceQueryBuilder) QueryRescorerBuilder(org.elasticsearch.search.rescore.QueryRescorerBuilder) TermSuggestionBuilder(org.elasticsearch.search.suggest.term.TermSuggestionBuilder) SearchPlugin(org.elasticsearch.plugins.SearchPlugin) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder) CumulativeSumPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregationBuilder) SearchRequest(org.elasticsearch.action.search.SearchRequest) InternalFilter(org.elasticsearch.search.aggregations.bucket.filter.InternalFilter) SamplerAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder) MinBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregator) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) FunctionScoreQueryBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder) AggregatorFactories(org.elasticsearch.search.aggregations.AggregatorFactories) FetchPhaseConstructionContext(org.elasticsearch.plugins.SearchPlugin.FetchPhaseConstructionContext) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder) MaxBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregator) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) GeoBoundingBoxQueryBuilder(org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder) VersionFetchSubPhase(org.elasticsearch.search.fetch.subphase.VersionFetchSubPhase) WildcardQueryBuilder(org.elasticsearch.index.query.WildcardQueryBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) DateHistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) InternalTopHits(org.elasticsearch.search.aggregations.metrics.tophits.InternalTopHits) InternalCardinality(org.elasticsearch.search.aggregations.metrics.cardinality.InternalCardinality) GND(org.elasticsearch.search.aggregations.bucket.significant.heuristics.GND) WeightBuilder(org.elasticsearch.index.query.functionscore.WeightBuilder) InternalMax(org.elasticsearch.search.aggregations.metrics.max.InternalMax) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) MinBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregationBuilder) Settings(org.elasticsearch.common.settings.Settings) ParentIdQueryBuilder(org.elasticsearch.index.query.ParentIdQueryBuilder) LinearModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.LinearModel) FieldMaskingSpanQueryBuilder(org.elasticsearch.index.query.FieldMaskingSpanQueryBuilder) CompletionSuggestionBuilder(org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder) BucketScriptPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregator) GeoBoundsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregationBuilder) ExponentialDecayFunctionBuilder(org.elasticsearch.index.query.functionscore.ExponentialDecayFunctionBuilder) BucketSelectorPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregator) InternalPercentilesBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.InternalPercentilesBucket) LinearDecayFunctionBuilder(org.elasticsearch.index.query.functionscore.LinearDecayFunctionBuilder) InternalHDRPercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentileRanks) GeoShapeQueryBuilder(org.elasticsearch.index.query.GeoShapeQueryBuilder) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) AvgBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregationBuilder) QueryParseContext(org.elasticsearch.index.query.QueryParseContext) ShapeBuilders(org.elasticsearch.common.geo.builders.ShapeBuilders) ReverseNestedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder) ScriptQueryBuilder(org.elasticsearch.index.query.ScriptQueryBuilder) TopHitsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregationBuilder) ExplainFetchSubPhase(org.elasticsearch.search.fetch.subphase.ExplainFetchSubPhase) BaseAggregationBuilder(org.elasticsearch.search.aggregations.BaseAggregationBuilder) PercentilesBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregationBuilder) DocValueFieldsFetchSubPhase(org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase) FetchPhase(org.elasticsearch.search.fetch.FetchPhase) MovAvgPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator) Laplace(org.elasticsearch.search.suggest.phrase.Laplace) InternalDateRange(org.elasticsearch.search.aggregations.bucket.range.date.InternalDateRange) SimpleModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel) QuerySpec(org.elasticsearch.plugins.SearchPlugin.QuerySpec) HighlightPhase(org.elasticsearch.search.fetch.subphase.highlight.HighlightPhase) Function(java.util.function.Function) PercentilesBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregator) UnifiedHighlighter(org.elasticsearch.search.fetch.subphase.highlight.UnifiedHighlighter) InternalRange(org.elasticsearch.search.aggregations.bucket.range.InternalRange) StringTerms(org.elasticsearch.search.aggregations.bucket.terms.StringTerms) SpanOrQueryBuilder(org.elasticsearch.index.query.SpanOrQueryBuilder) MoreLikeThisQueryBuilder(org.elasticsearch.index.query.MoreLikeThisQueryBuilder) StatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.StatsAggregationBuilder) FiltersAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder) PipelineAggregator(org.elasticsearch.search.aggregations.pipeline.PipelineAggregator) InternalExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats) InternalAvg(org.elasticsearch.search.aggregations.metrics.avg.InternalAvg) SearchExtensionSpec(org.elasticsearch.plugins.SearchPlugin.SearchExtensionSpec) PipelineAggregationSpec(org.elasticsearch.plugins.SearchPlugin.PipelineAggregationSpec) HistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder) FetchSourceSubPhase(org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) Consumer(java.util.function.Consumer) SearchExtSpec(org.elasticsearch.plugins.SearchPlugin.SearchExtSpec) HasChildQueryBuilder(org.elasticsearch.index.query.HasChildQueryBuilder) BucketSelectorPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregationBuilder) DoubleTerms(org.elasticsearch.search.aggregations.bucket.terms.DoubleTerms) Entry(org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry) ScoreFunctionSpec(org.elasticsearch.plugins.SearchPlugin.ScoreFunctionSpec) JLHScore(org.elasticsearch.search.aggregations.bucket.significant.heuristics.JLHScore) GaussDecayFunctionBuilder(org.elasticsearch.index.query.functionscore.GaussDecayFunctionBuilder) IpRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.ip.IpRangeAggregationBuilder) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) PlainHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PlainHighlighter) InternalNested(org.elasticsearch.search.aggregations.bucket.nested.InternalNested) MovAvgModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel) ChildrenAggregationBuilder(org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregationBuilder) EwmaModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.EwmaModel) InternalStatsBucket(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.InternalStatsBucket) CardinalityAggregationBuilder(org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregationBuilder) SuggestionBuilder(org.elasticsearch.search.suggest.SuggestionBuilder) InternalValueCount(org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCount) InternalSum(org.elasticsearch.search.aggregations.metrics.sum.InternalSum) SpanFirstQueryBuilder(org.elasticsearch.index.query.SpanFirstQueryBuilder) SpanTermQueryBuilder(org.elasticsearch.index.query.SpanTermQueryBuilder) SumBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator) GeoGridAggregationBuilder(org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder) CumulativeSumPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregator) StupidBackoff(org.elasticsearch.search.suggest.phrase.StupidBackoff) InternalGlobal(org.elasticsearch.search.aggregations.bucket.global.InternalGlobal) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) TypeQueryBuilder(org.elasticsearch.index.query.TypeQueryBuilder) LinearInterpolation(org.elasticsearch.search.suggest.phrase.LinearInterpolation) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) SpanContainingQueryBuilder(org.elasticsearch.index.query.SpanContainingQueryBuilder) ParseFieldRegistry(org.elasticsearch.common.xcontent.ParseFieldRegistry) DiversifiedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedAggregationBuilder) ExistsQueryBuilder(org.elasticsearch.index.query.ExistsQueryBuilder) NestedQueryBuilder(org.elasticsearch.index.query.NestedQueryBuilder) InternalGeoCentroid(org.elasticsearch.search.aggregations.metrics.geocentroid.InternalGeoCentroid) StatsBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregator) WrapperQueryBuilder(org.elasticsearch.index.query.WrapperQueryBuilder) HoltLinearModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltLinearModel) GeoCentroidAggregationBuilder(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregationBuilder) InternalSimpleValue(org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue) MatchPhraseQueryBuilder(org.elasticsearch.index.query.MatchPhraseQueryBuilder) InternalSampler(org.elasticsearch.search.aggregations.bucket.sampler.InternalSampler) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) InternalAdjacencyMatrix(org.elasticsearch.search.aggregations.bucket.adjacency.InternalAdjacencyMatrix) StatsBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregationBuilder) SimpleQueryStringBuilder(org.elasticsearch.index.query.SimpleQueryStringBuilder) ConstantScoreQueryBuilder(org.elasticsearch.index.query.ConstantScoreQueryBuilder) AvgBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregator) SerialDiffPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregationBuilder) RegexpQueryBuilder(org.elasticsearch.index.query.RegexpQueryBuilder) PercentageScore(org.elasticsearch.search.aggregations.bucket.significant.heuristics.PercentageScore) InternalStats(org.elasticsearch.search.aggregations.metrics.stats.InternalStats) SpanNearQueryBuilder(org.elasticsearch.index.query.SpanNearQueryBuilder) ArrayList(java.util.ArrayList) InternalChildren(org.elasticsearch.search.aggregations.bucket.children.InternalChildren) BiConsumer(java.util.function.BiConsumer) ExtendedStatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder) MaxBucketPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregationBuilder) SortBuilder(org.elasticsearch.search.sort.SortBuilder) SignificanceHeuristic(org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristic) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) InternalHDRPercentiles(org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentiles) ParentFieldSubFetchPhase(org.elasticsearch.search.fetch.subphase.ParentFieldSubFetchPhase) MatchNoneQueryBuilder(org.elasticsearch.index.query.MatchNoneQueryBuilder) GlobalAggregationBuilder(org.elasticsearch.search.aggregations.bucket.global.GlobalAggregationBuilder) InternalDateHistogram(org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram) SpanMultiTermQueryBuilder(org.elasticsearch.index.query.SpanMultiTermQueryBuilder) ShapesAvailability(org.elasticsearch.common.geo.ShapesAvailability) GeoPolygonQueryBuilder(org.elasticsearch.index.query.GeoPolygonQueryBuilder) Highlighter(org.elasticsearch.search.fetch.subphase.highlight.Highlighter) PostingsHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PostingsHighlighter) SmoothingModel(org.elasticsearch.search.suggest.phrase.SmoothingModel) BoostingQueryBuilder(org.elasticsearch.index.query.BoostingQueryBuilder) InternalScriptedMetric(org.elasticsearch.search.aggregations.metrics.scripted.InternalScriptedMetric) GeoDistanceAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceAggregationBuilder) ExtendedStatsBucketPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregator) BucketScriptPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregationBuilder) InternalHistogram(org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram) ScriptSortBuilder(org.elasticsearch.search.sort.ScriptSortBuilder) PipelineAggregationBuilder(org.elasticsearch.search.aggregations.PipelineAggregationBuilder) PrefixQueryBuilder(org.elasticsearch.index.query.PrefixQueryBuilder) RescoreBuilder(org.elasticsearch.search.rescore.RescoreBuilder) InternalMin(org.elasticsearch.search.aggregations.metrics.min.InternalMin) MatchPhrasePrefixQueryBuilder(org.elasticsearch.index.query.MatchPhrasePrefixQueryBuilder) SignificantStringTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantStringTerms) PercentileRanksAggregationBuilder(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregationBuilder) ScriptFieldsFetchSubPhase(org.elasticsearch.search.fetch.subphase.ScriptFieldsFetchSubPhase) SearchResponse(org.elasticsearch.action.search.SearchResponse) MinAggregationBuilder(org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder) SpanWithinQueryBuilder(org.elasticsearch.index.query.SpanWithinQueryBuilder) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) MissingAggregationBuilder(org.elasticsearch.search.aggregations.bucket.missing.MissingAggregationBuilder) Setting(org.elasticsearch.common.settings.Setting) MatchedQueriesFetchSubPhase(org.elasticsearch.search.fetch.subphase.MatchedQueriesFetchSubPhase) InternalTDigestPercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentileRanks) InternalBucketMetricValue(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue) HoltWintersModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.HoltWintersModel) ScoreSortBuilder(org.elasticsearch.search.sort.ScoreSortBuilder) ScriptedMetricAggregationBuilder(org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregationBuilder) SerialDiffPipelineAggregator(org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator) List(java.util.List) UnmappedSignificantTerms(org.elasticsearch.search.aggregations.bucket.significant.UnmappedSignificantTerms) ChiSquare(org.elasticsearch.search.aggregations.bucket.significant.heuristics.ChiSquare) ValueCountAggregationBuilder(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregationBuilder) ScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) InternalGeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid) UnmappedTerms(org.elasticsearch.search.aggregations.bucket.terms.UnmappedTerms) AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) ExtendedStatsBucketParser(org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketParser) SpanNotQueryBuilder(org.elasticsearch.index.query.SpanNotQueryBuilder) DateRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder) DerivativePipelineAggregator(org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator) FetchSubPhase(org.elasticsearch.search.fetch.FetchSubPhase) PercentilesAggregationBuilder(org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesAggregationBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder) Objects.requireNonNull(java.util.Objects.requireNonNull) AdjacencyMatrixAggregationBuilder(org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder) InternalMissing(org.elasticsearch.search.aggregations.bucket.missing.InternalMissing) InternalBinaryRange(org.elasticsearch.search.aggregations.bucket.range.InternalBinaryRange) MovAvgPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregationBuilder) SignificantLongTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantLongTerms) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) AvgAggregationBuilder(org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder) PhraseSuggestionBuilder(org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilder) AggregationSpec(org.elasticsearch.plugins.SearchPlugin.AggregationSpec) BooleanQuery(org.apache.lucene.search.BooleanQuery) InternalFilters(org.elasticsearch.search.aggregations.bucket.filters.InternalFilters) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) InternalTDigestPercentiles(org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentiles) Writeable(org.elasticsearch.common.io.stream.Writeable) ScriptHeuristic(org.elasticsearch.search.aggregations.bucket.significant.heuristics.ScriptHeuristic) FuzzyQueryBuilder(org.elasticsearch.index.query.FuzzyQueryBuilder) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) HasParentQueryBuilder(org.elasticsearch.index.query.HasParentQueryBuilder) GeoDistanceQueryBuilder(org.elasticsearch.index.query.GeoDistanceQueryBuilder) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder) FunctionScoreQueryBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) GeoBoundingBoxQueryBuilder(org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder) WildcardQueryBuilder(org.elasticsearch.index.query.WildcardQueryBuilder) ParentIdQueryBuilder(org.elasticsearch.index.query.ParentIdQueryBuilder) FieldMaskingSpanQueryBuilder(org.elasticsearch.index.query.FieldMaskingSpanQueryBuilder) GeoShapeQueryBuilder(org.elasticsearch.index.query.GeoShapeQueryBuilder) ScriptQueryBuilder(org.elasticsearch.index.query.ScriptQueryBuilder) SpanOrQueryBuilder(org.elasticsearch.index.query.SpanOrQueryBuilder) MoreLikeThisQueryBuilder(org.elasticsearch.index.query.MoreLikeThisQueryBuilder) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) HasChildQueryBuilder(org.elasticsearch.index.query.HasChildQueryBuilder) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) SpanFirstQueryBuilder(org.elasticsearch.index.query.SpanFirstQueryBuilder) SpanTermQueryBuilder(org.elasticsearch.index.query.SpanTermQueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) TypeQueryBuilder(org.elasticsearch.index.query.TypeQueryBuilder) SpanContainingQueryBuilder(org.elasticsearch.index.query.SpanContainingQueryBuilder) ExistsQueryBuilder(org.elasticsearch.index.query.ExistsQueryBuilder) NestedQueryBuilder(org.elasticsearch.index.query.NestedQueryBuilder) WrapperQueryBuilder(org.elasticsearch.index.query.WrapperQueryBuilder) MatchPhraseQueryBuilder(org.elasticsearch.index.query.MatchPhraseQueryBuilder) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) ConstantScoreQueryBuilder(org.elasticsearch.index.query.ConstantScoreQueryBuilder) RegexpQueryBuilder(org.elasticsearch.index.query.RegexpQueryBuilder) SpanNearQueryBuilder(org.elasticsearch.index.query.SpanNearQueryBuilder) MatchNoneQueryBuilder(org.elasticsearch.index.query.MatchNoneQueryBuilder) SpanMultiTermQueryBuilder(org.elasticsearch.index.query.SpanMultiTermQueryBuilder) GeoPolygonQueryBuilder(org.elasticsearch.index.query.GeoPolygonQueryBuilder) BoostingQueryBuilder(org.elasticsearch.index.query.BoostingQueryBuilder) PrefixQueryBuilder(org.elasticsearch.index.query.PrefixQueryBuilder) MatchPhrasePrefixQueryBuilder(org.elasticsearch.index.query.MatchPhrasePrefixQueryBuilder) SpanWithinQueryBuilder(org.elasticsearch.index.query.SpanWithinQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) SpanNotQueryBuilder(org.elasticsearch.index.query.SpanNotQueryBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) FuzzyQueryBuilder(org.elasticsearch.index.query.FuzzyQueryBuilder) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Entry(org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry)

Example 25 with QueryParseContext

use of org.elasticsearch.index.query.QueryParseContext in project elasticsearch by elastic.

the class SignificantTermsAggregationBuilder method getParser.

public static Aggregator.Parser getParser(ParseFieldRegistry<SignificanceHeuristicParser> significanceHeuristicParserRegistry) {
    ObjectParser<SignificantTermsAggregationBuilder, QueryParseContext> parser = new ObjectParser<>(SignificantTermsAggregationBuilder.NAME);
    ValuesSourceParserHelper.declareAnyFields(parser, true, true);
    parser.declareInt(SignificantTermsAggregationBuilder::shardSize, TermsAggregationBuilder.SHARD_SIZE_FIELD_NAME);
    parser.declareLong(SignificantTermsAggregationBuilder::minDocCount, TermsAggregationBuilder.MIN_DOC_COUNT_FIELD_NAME);
    parser.declareLong(SignificantTermsAggregationBuilder::shardMinDocCount, TermsAggregationBuilder.SHARD_MIN_DOC_COUNT_FIELD_NAME);
    parser.declareInt(SignificantTermsAggregationBuilder::size, TermsAggregationBuilder.REQUIRED_SIZE_FIELD_NAME);
    parser.declareString(SignificantTermsAggregationBuilder::executionHint, TermsAggregationBuilder.EXECUTION_HINT_FIELD_NAME);
    parser.declareObject(SignificantTermsAggregationBuilder::backgroundFilter, (p, context) -> context.parseInnerQueryBuilder(), SignificantTermsAggregationBuilder.BACKGROUND_FILTER);
    parser.declareField((b, v) -> b.includeExclude(IncludeExclude.merge(v, b.includeExclude())), IncludeExclude::parseInclude, IncludeExclude.INCLUDE_FIELD, ObjectParser.ValueType.OBJECT_ARRAY_OR_STRING);
    parser.declareField((b, v) -> b.includeExclude(IncludeExclude.merge(b.includeExclude(), v)), IncludeExclude::parseExclude, IncludeExclude.EXCLUDE_FIELD, ObjectParser.ValueType.STRING_ARRAY);
    for (String name : significanceHeuristicParserRegistry.getNames()) {
        parser.declareObject(SignificantTermsAggregationBuilder::significanceHeuristic, (p, context) -> {
            SignificanceHeuristicParser significanceHeuristicParser = significanceHeuristicParserRegistry.lookupReturningNullIfNotFound(name);
            return significanceHeuristicParser.parse(context);
        }, new ParseField(name));
    }
    return new Aggregator.Parser() {

        @Override
        public AggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
            return parser.parse(context.parser(), new SignificantTermsAggregationBuilder(aggregationName, null), context);
        }
    };
}
Also used : ObjectParser(org.elasticsearch.common.xcontent.ObjectParser) QueryParseContext(org.elasticsearch.index.query.QueryParseContext) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude) SignificanceHeuristicParser(org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser) ParseField(org.elasticsearch.common.ParseField) SignificanceHeuristicParser(org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser) ObjectParser(org.elasticsearch.common.xcontent.ObjectParser)

Aggregations

QueryParseContext (org.elasticsearch.index.query.QueryParseContext)55 XContentParser (org.elasticsearch.common.xcontent.XContentParser)45 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)14 ParsingException (org.elasticsearch.common.ParsingException)12 IOException (java.io.IOException)7 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)5 ArrayList (java.util.ArrayList)2 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)2 List (java.util.List)2 Map (java.util.Map)2 Consumer (java.util.function.Consumer)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 BytesReference (org.elasticsearch.common.bytes.BytesReference)2 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)2 SignificanceHeuristicParser (org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser)2 IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude)2 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)2 SearchContext (org.elasticsearch.search.internal.SearchContext)2