java.lang.Object
org.elasticsearch.index.query.QueryRewriteContext
- Direct Known Subclasses:
CoordinatorRewriteContext,DataRewriteContext,InnerHitsRewriteContext,SearchExecutionContext
Context object used to rewrite
QueryBuilder instances into simplified version.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BooleanSupplierprotected booleanprotected final Clientprotected final Indexprotected final IndexSettingsprotected final MapperServiceprotected final MappingLookupprotected booleanprotected final LongSupplierprotected final Map<String, MappedFieldType> protected final ScriptCompilerprotected final ValuesSourceRegistryprotected final NamedWriteableRegistry -
Constructor Summary
ConstructorsConstructorDescriptionQueryRewriteContext(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis) QueryRewriteContext(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis, ResolvedIndices resolvedIndices, PointInTimeBuilder pit, QueryRewriteInterceptor queryRewriteInterceptor) QueryRewriteContext(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis, ResolvedIndices resolvedIndices, PointInTimeBuilder pit, QueryRewriteInterceptor queryRewriteInterceptor, boolean isExplain) QueryRewriteContext(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis, MapperService mapperService, MappingLookup mappingLookup, Map<String, MappedFieldType> runtimeMappings, IndexSettings indexSettings, Index fullyQualifiedIndex, Predicate<String> indexNameMatcher, NamedWriteableRegistry namedWriteableRegistry, ValuesSourceRegistry valuesSourceRegistry, BooleanSupplier allowExpensiveQueries, ScriptCompiler scriptService, ResolvedIndices resolvedIndices, PointInTimeBuilder pit, QueryRewriteInterceptor queryRewriteInterceptor, boolean isExplain) -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns an instance ofCoordinatorRewriteContextif available or null otherwiseReturns an instance ofDataRewriteContextif available or null otherwiseReturns an instance ofSearchExecutionContextif available or null otherwisevoidexecuteAsyncActions(ActionListener<Void> listener) Executes all registered async actions and notifies the listener once it's done.protected MappedFieldTypegetFieldType(String name) Returns theMappedFieldTypefor the provided field name.Returns the fully qualified index including a remote cluster alias if applicable, and the index uuidReturns the index settings for this context.Returns the MappingLookup for the queried index.getMatchingFieldNames(String pattern) Returns the names of all mapped fields that match a given pattern All names returned by this method are guaranteed to resolve to a MappedFieldType if passed togetFieldType(String)The registry used to build newXContentParsers.Returns thePointInTimeBuilderused by the search request, or null if not specified.Retrieve the first tier preference from the index setting.booleanReturnstrueif there are any registered async actions.booleanindexMatches(String pattern) Given an index pattern, checks whether it matches against the current shard.booleanlongReturns the time in milliseconds that is shared across all resources involved.voidregisterAsyncAction(BiConsumer<Client, ActionListener<?>> asyncAction) Registers an async action that must be executed before the next rewrite round in order to make progress.voidsetAllowUnmappedFields(boolean allowUnmappedFields) voidsetMapUnmappedFieldAsString(boolean mapUnmappedFieldAsString) voidsetQueryRewriteInterceptor(QueryRewriteInterceptor queryRewriteInterceptor)
-
Field Details
-
mapperService
-
mappingLookup
-
runtimeMappings
-
indexSettings
-
fullyQualifiedIndex
-
indexNameMatcher
-
writeableRegistry
-
valuesSourceRegistry
-
allowExpensiveQueries
-
scriptService
-
client
-
nowInMillis
-
allowUnmappedFields
protected boolean allowUnmappedFields -
mapUnmappedFieldAsString
protected boolean mapUnmappedFieldAsString -
allowedFields
-
-
Constructor Details
-
QueryRewriteContext
public QueryRewriteContext(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis, MapperService mapperService, MappingLookup mappingLookup, Map<String, MappedFieldType> runtimeMappings, IndexSettings indexSettings, Index fullyQualifiedIndex, Predicate<String> indexNameMatcher, NamedWriteableRegistry namedWriteableRegistry, ValuesSourceRegistry valuesSourceRegistry, BooleanSupplier allowExpensiveQueries, ScriptCompiler scriptService, ResolvedIndices resolvedIndices, PointInTimeBuilder pit, QueryRewriteInterceptor queryRewriteInterceptor, boolean isExplain) -
QueryRewriteContext
public QueryRewriteContext(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis) -
QueryRewriteContext
public QueryRewriteContext(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis, ResolvedIndices resolvedIndices, PointInTimeBuilder pit, QueryRewriteInterceptor queryRewriteInterceptor) -
QueryRewriteContext
public QueryRewriteContext(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis, ResolvedIndices resolvedIndices, PointInTimeBuilder pit, QueryRewriteInterceptor queryRewriteInterceptor, boolean isExplain)
-
-
Method Details
-
getParserConfig
The registry used to build newXContentParsers. Contains registered named parsers needed to parse the query. Used by WrapperQueryBuilder -
nowInMillis
public long nowInMillis()Returns the time in milliseconds that is shared across all resources involved. Even across shards and nodes. Used in date field query rewriting -
convertToSearchExecutionContext
Returns an instance ofSearchExecutionContextif available or null otherwise -
convertToCoordinatorRewriteContext
Returns an instance ofCoordinatorRewriteContextif available or null otherwise -
convertToIndexMetadataContext
- Returns:
- an
QueryRewriteContextinstance that is aware of the mapping and other index metadata ornullotherwise.
-
convertToDataRewriteContext
Returns an instance ofDataRewriteContextif available or null otherwise -
convertToInnerHitsRewriteContext
-
getFieldType
Returns theMappedFieldTypefor the provided field name. If the field is not mapped, the behaviour depends on the index.query.parse.allow_unmapped_fields setting, which defaults to true. In case unmapped fields are allowed, null is returned when the field is not mapped. In case unmapped fields are not allowed, either an exception is thrown or the field is automatically mapped as a text field.- Throws:
QueryShardException- if unmapped fields are not allowed and automatically mapping unmapped fields as text is disabled.- See Also:
-
fieldType
-
getIndexAnalyzers
-
setAllowUnmappedFields
public void setAllowUnmappedFields(boolean allowUnmappedFields) -
setMapUnmappedFieldAsString
public void setMapUnmappedFieldAsString(boolean mapUnmappedFieldAsString) -
isExplain
public boolean isExplain() -
getWriteableRegistry
-
getValuesSourceRegistry
-
allowExpensiveQueries
public boolean allowExpensiveQueries() -
registerAsyncAction
Registers an async action that must be executed before the next rewrite round in order to make progress. This should be used if a rewriteable needs to fetch some external resources in order to be executed ie. a document from an index. -
hasAsyncActions
public boolean hasAsyncActions()Returnstrueif there are any registered async actions. -
executeAsyncActions
Executes all registered async actions and notifies the listener once it's done. The value that is passed to the listener is alwaysnull. The list of registered actions is cleared once this method returns. -
getFullyQualifiedIndex
Returns the fully qualified index including a remote cluster alias if applicable, and the index uuid -
getIndexSettings
Returns the index settings for this context. This might return null if the context has not index scope. -
getMappingLookup
Returns the MappingLookup for the queried index. -
indexMatches
Given an index pattern, checks whether it matches against the current shard. The pattern may represent a fully qualified index name if the search targets remote shards. -
getMatchingFieldNames
Returns the names of all mapped fields that match a given pattern All names returned by this method are guaranteed to resolve to a MappedFieldType if passed togetFieldType(String)- Parameters:
pattern- the field name pattern
-
getAllFields
- Returns:
- An
Iterablewith key the field name and value the MappedFieldType
-
getResolvedIndices
-
getPointInTimeBuilder
Returns thePointInTimeBuilderused by the search request, or null if not specified. -
getTierPreference
Retrieve the first tier preference from the index setting. If the setting is not present, then return null. -
getQueryRewriteInterceptor
-
setQueryRewriteInterceptor
-