Package org.elasticsearch.index.query
Class QueryShardContext
- java.lang.Object
-
- org.elasticsearch.index.query.QueryRewriteContext
-
- org.elasticsearch.index.query.QueryShardContext
-
public class QueryShardContext extends QueryRewriteContext
Context object used to create lucene queries on the shard level.
-
-
Field Summary
-
Fields inherited from class org.elasticsearch.index.query.QueryRewriteContext
client, nowInMillis
-
-
Constructor Summary
Constructors Constructor Description QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache, java.util.function.Function<org.apache.lucene.index.IndexReaderContext,org.apache.lucene.search.IndexSearcher> searcherFactory, java.util.function.BiFunction<MappedFieldType,java.lang.String,IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService, SimilarityService similarityService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, NamedWriteableRegistry namedWriteableRegistry, Client client, org.apache.lucene.index.IndexReader reader, java.util.function.LongSupplier nowInMillis, java.lang.String clusterAlias)
QueryShardContext(QueryShardContext source)
-
Method Summary
Modifier and Type Method Description void
addNamedQuery(java.lang.String name, org.apache.lucene.search.Query query)
org.apache.lucene.search.join.BitSetProducer
bitsetFilter(org.apache.lucene.search.Query filter)
QueryShardContext
convertToShardContext()
Returns an instance ofQueryShardContext
if available of null otherwisejava.util.Map<java.lang.String,org.apache.lucene.search.Query>
copyNamedQueries()
java.util.List<java.lang.String>
defaultFields()
DocumentMapper
documentMapper(java.lang.String type)
Returns sDocumentMapper
instance for the given type.void
executeAsyncActions(ActionListener listener)
Executes all registered async actions and notifies the listener once it's done.protected void
failIfFrozen()
This method fails iffreezeContext()
is called before on this context.MappedFieldType
fieldMapper(java.lang.String name)
void
freezeContext()
if this method is called the query context will throw exception if methods are accessed that could yield different results across executions likegetClient()
Client
getClient()
<IFD extends IndexFieldData<?>>
IFDgetForField(MappedFieldType fieldType)
Index
getFullyQualifiedIndex()
Returns the fully qualified index including a remote cluster alias if applicable, and the index uuidIndexAnalyzers
getIndexAnalyzers()
org.apache.lucene.index.IndexReader
getIndexReader()
Return the currentIndexReader
, ornull
if no index reader is available, for instance if this rewrite context is used to index queries (percolation).IndexSettings
getIndexSettings()
Returns the index settings for this context.MapperService
getMapperService()
Return the MapperService.ObjectMapper
getObjectMapper(java.lang.String name)
ScriptService
getScriptService()
Return the script service to allow compiling scripts.org.apache.lucene.analysis.Analyzer
getSearchAnalyzer(MappedFieldType fieldType)
Gets the search analyzer for the given field, or the default if there is none present for the field TODO: remove this by moving defaults into mappers themselvesorg.apache.lucene.analysis.Analyzer
getSearchQuoteAnalyzer(MappedFieldType fieldType)
Gets the search quote analyzer for the given field, or the default if there is none present for the field TODO: remove this by moving defaults into mappers themselvesorg.apache.lucene.search.similarities.Similarity
getSearchSimilarity()
int
getShardId()
Returns the shard ID this context was created for.java.lang.String[]
getTypes()
Index
index()
Version
indexVersionCreated()
boolean
isCacheable()
Returnstrue
iff the result of the processed search request is cacheable.boolean
isFilter()
Deprecated.The distinction between query and filter context is removed in the next major version.SearchLookup
lookup()
NestedScope
nestedScope()
org.apache.lucene.search.IndexSearcher
newCachedSearcher(org.apache.lucene.index.IndexReaderContext context)
long
nowInMillis()
Returns the time in milliseconds that is shared across all resources involved.QueryBuilder
parseInnerQueryBuilder(XContentParser parser)
boolean
queryStringAllowLeadingWildcard()
boolean
queryStringAnalyzeWildcard()
boolean
queryStringLenient()
java.util.Collection<java.lang.String>
queryTypes()
Returns the narrowed down explicit types, or, if not set, all types.void
registerAsyncAction(java.util.function.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
setIsFilter(boolean isFilter)
Public for testing only! Sets whether we are currently parsing a filter or a queryvoid
setMapUnmappedFieldAsString(boolean mapUnmappedFieldAsString)
void
setTypes(java.lang.String... types)
java.util.Collection<java.lang.String>
simpleMatchToIndexNames(java.lang.String pattern)
Returns all the fields that match a given pattern.ParsedQuery
toFilter(QueryBuilder queryBuilder)
ParsedQuery
toQuery(QueryBuilder queryBuilder)
-
Methods inherited from class org.elasticsearch.index.query.QueryRewriteContext
convertNowRangeToMatchAll, getWriteableRegistry, getXContentRegistry, hasAsyncActions
-
-
-
-
Constructor Detail
-
QueryShardContext
public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache, java.util.function.Function<org.apache.lucene.index.IndexReaderContext,org.apache.lucene.search.IndexSearcher> searcherFactory, java.util.function.BiFunction<MappedFieldType,java.lang.String,IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService, SimilarityService similarityService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, NamedWriteableRegistry namedWriteableRegistry, Client client, org.apache.lucene.index.IndexReader reader, java.util.function.LongSupplier nowInMillis, java.lang.String clusterAlias)
-
QueryShardContext
public QueryShardContext(QueryShardContext source)
-
-
Method Detail
-
setTypes
public void setTypes(java.lang.String... types)
-
getTypes
public java.lang.String[] getTypes()
-
getIndexAnalyzers
public IndexAnalyzers getIndexAnalyzers()
-
getSearchSimilarity
public org.apache.lucene.search.similarities.Similarity getSearchSimilarity()
-
defaultFields
public java.util.List<java.lang.String> defaultFields()
-
queryStringLenient
public boolean queryStringLenient()
-
queryStringAnalyzeWildcard
public boolean queryStringAnalyzeWildcard()
-
queryStringAllowLeadingWildcard
public boolean queryStringAllowLeadingWildcard()
-
bitsetFilter
public org.apache.lucene.search.join.BitSetProducer bitsetFilter(org.apache.lucene.search.Query filter)
-
newCachedSearcher
public org.apache.lucene.search.IndexSearcher newCachedSearcher(org.apache.lucene.index.IndexReaderContext context)
-
getForField
public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType)
-
addNamedQuery
public void addNamedQuery(java.lang.String name, org.apache.lucene.search.Query query)
-
copyNamedQueries
public java.util.Map<java.lang.String,org.apache.lucene.search.Query> copyNamedQueries()
-
isFilter
@Deprecated public boolean isFilter()
Deprecated.The distinction between query and filter context is removed in the next major version.Return whether we are currently parsing a filter or a query.
-
setIsFilter
public void setIsFilter(boolean isFilter)
Public for testing only! Sets whether we are currently parsing a filter or a query
-
simpleMatchToIndexNames
public java.util.Collection<java.lang.String> simpleMatchToIndexNames(java.lang.String pattern)
Returns all the fields that match a given pattern. If prefixed with a type then the fields will be returned with a type prefix.
-
fieldMapper
public MappedFieldType fieldMapper(java.lang.String name)
-
getObjectMapper
public ObjectMapper getObjectMapper(java.lang.String name)
-
documentMapper
public DocumentMapper documentMapper(java.lang.String type)
Returns sDocumentMapper
instance for the given type. Delegates toMapperService.documentMapper(String)
-
getSearchAnalyzer
public org.apache.lucene.analysis.Analyzer getSearchAnalyzer(MappedFieldType fieldType)
Gets the search analyzer for the given field, or the default if there is none present for the field TODO: remove this by moving defaults into mappers themselves
-
getSearchQuoteAnalyzer
public org.apache.lucene.analysis.Analyzer getSearchQuoteAnalyzer(MappedFieldType fieldType)
Gets the search quote analyzer for the given field, or the default if there is none present for the field TODO: remove this by moving defaults into mappers themselves
-
setAllowUnmappedFields
public void setAllowUnmappedFields(boolean allowUnmappedFields)
-
setMapUnmappedFieldAsString
public void setMapUnmappedFieldAsString(boolean mapUnmappedFieldAsString)
-
queryTypes
public java.util.Collection<java.lang.String> queryTypes()
Returns the narrowed down explicit types, or, if not set, all types.
-
lookup
public SearchLookup lookup()
-
nestedScope
public NestedScope nestedScope()
-
indexVersionCreated
public Version indexVersionCreated()
-
toFilter
public ParsedQuery toFilter(QueryBuilder queryBuilder)
-
toQuery
public ParsedQuery toQuery(QueryBuilder queryBuilder)
-
index
public Index index()
-
getScriptService
public final ScriptService getScriptService()
Return the script service to allow compiling scripts.
-
freezeContext
public final void freezeContext()
if this method is called the query context will throw exception if methods are accessed that could yield different results across executions likegetClient()
-
failIfFrozen
protected final void failIfFrozen()
This method fails iffreezeContext()
is called before on this context. This is used to seal. This methods and all methods that call it should be final to ensure that setting the request as not cacheable and the freezing behaviour of this class cannot be bypassed. This is important so we can trust when this class says a request can be cached.
-
registerAsyncAction
public void registerAsyncAction(java.util.function.BiConsumer<Client,ActionListener<?>> asyncAction)
Description copied from class:QueryRewriteContext
Registers an async action that must be executed before the next rewrite round in order to make progress. This should be used if a rewriteabel needs to fetch some external resources in order to be executed ie. a document from an index.- Overrides:
registerAsyncAction
in classQueryRewriteContext
-
executeAsyncActions
public void executeAsyncActions(ActionListener listener)
Description copied from class:QueryRewriteContext
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.- Overrides:
executeAsyncActions
in classQueryRewriteContext
-
isCacheable
public final boolean isCacheable()
Returnstrue
iff the result of the processed search request is cacheable. Otherwisefalse
-
getShardId
public int getShardId()
Returns the shard ID this context was created for.
-
nowInMillis
public final long nowInMillis()
Description copied from class:QueryRewriteContext
Returns the time in milliseconds that is shared across all resources involved. Even across shards and nodes.- Overrides:
nowInMillis
in classQueryRewriteContext
-
getClient
public Client getClient()
-
parseInnerQueryBuilder
public QueryBuilder parseInnerQueryBuilder(XContentParser parser) throws java.io.IOException
- Throws:
java.io.IOException
-
convertToShardContext
public final QueryShardContext convertToShardContext()
Description copied from class:QueryRewriteContext
Returns an instance ofQueryShardContext
if available of null otherwise- Overrides:
convertToShardContext
in classQueryRewriteContext
-
getIndexSettings
public IndexSettings getIndexSettings()
Returns the index settings for this context. This might return null if the context has not index scope.
-
getMapperService
public MapperService getMapperService()
Return the MapperService.
-
getIndexReader
public org.apache.lucene.index.IndexReader getIndexReader()
Return the currentIndexReader
, ornull
if no index reader is available, for instance if this rewrite context is used to index queries (percolation).
-
getFullyQualifiedIndex
public Index getFullyQualifiedIndex()
Returns the fully qualified index including a remote cluster alias if applicable, and the index uuid
-
-