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
Modifier and TypeFieldDescriptionprotected final BooleanSupplier
protected boolean
protected final Client
protected final Index
protected final IndexSettings
protected final MapperService
protected final MappingLookup
protected boolean
protected final LongSupplier
protected final Map<String,
MappedFieldType> protected final ScriptCompiler
protected final ValuesSourceRegistry
protected final NamedWriteableRegistry
-
Constructor Summary
ConstructorDescriptionQueryRewriteContext
(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis) QueryRewriteContext
(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis, MapperService mapperService, MappingLookup mappingLookup, Map<String, MappedFieldType> runtimeMappings, Predicate<String> allowedFields, IndexSettings indexSettings, Index fullyQualifiedIndex, Predicate<String> indexNameMatcher, NamedWriteableRegistry namedWriteableRegistry, ValuesSourceRegistry valuesSourceRegistry, BooleanSupplier allowExpensiveQueries, ScriptCompiler scriptService) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns an instance ofCoordinatorRewriteContext
if available or null otherwiseReturns an instance ofDataRewriteContext
if available or null otherwiseReturns an instance ofSearchExecutionContext
if available or null otherwisevoid
executeAsyncActions
(ActionListener listener) Executes all registered async actions and notifies the listener once it's done.protected MappedFieldType
getFieldType
(String name) Returns theMappedFieldType
for 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 newXContentParser
s.boolean
Returnstrue
if there are any registered async actions.boolean
indexMatches
(String pattern) Given an index pattern, checks whether it matches against the current shard.long
Returns the time in milliseconds that is shared across all resources involved.void
registerAsyncAction
(BiConsumer<Client, ActionListener<?>> asyncAction) Registers an async action that must be executed before the next rewrite round in order to make progress.void
setAllowUnmappedFields
(boolean allowUnmappedFields) void
setMapUnmappedFieldAsString
(boolean mapUnmappedFieldAsString)
-
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, Predicate<String> allowedFields, IndexSettings indexSettings, Index fullyQualifiedIndex, Predicate<String> indexNameMatcher, NamedWriteableRegistry namedWriteableRegistry, ValuesSourceRegistry valuesSourceRegistry, BooleanSupplier allowExpensiveQueries, ScriptCompiler scriptService) -
QueryRewriteContext
public QueryRewriteContext(XContentParserConfiguration parserConfiguration, Client client, LongSupplier nowInMillis)
-
-
Method Details
-
getParserConfig
The registry used to build newXContentParser
s. 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 ofSearchExecutionContext
if available or null otherwise -
convertToCoordinatorRewriteContext
Returns an instance ofCoordinatorRewriteContext
if available or null otherwise -
convertToIndexMetadataContext
- Returns:
- an
QueryRewriteContext
instance that is aware of the mapping and other index metadata ornull
otherwise.
-
convertToDataRewriteContext
Returns an instance ofDataRewriteContext
if available or null otherwise -
convertToInnerHitsRewriteContext
-
getFieldType
Returns theMappedFieldType
for 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) -
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()Returnstrue
if 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
Iterable
with key the field name and value the MappedFieldType
-