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
-
Constructor Summary
Constructors Constructor Description QueryShardContext(int shardId, IndexSettings indexSettings, BigArrays bigArrays, BitsetFilterCache bitsetFilterCache, TriFunction<MappedFieldType,java.lang.String,java.util.function.Supplier<SearchLookup>,IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService, MappingLookup mappingLookup, SimilarityService similarityService, ScriptService scriptService, org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, NamedWriteableRegistry namedWriteableRegistry, Client client, org.apache.lucene.search.IndexSearcher searcher, java.util.function.LongSupplier nowInMillis, java.lang.String clusterAlias, java.util.function.Predicate<java.lang.String> indexNameMatcher, java.util.function.BooleanSupplier allowExpensiveQueries, ValuesSourceRegistry valuesSourceRegistry, java.util.Map<java.lang.String,java.lang.Object> runtimeMappings)Build a QueryShardContext.QueryShardContext(QueryShardContext source) -
Method Summary
Modifier and Type Method Description voidaddNamedQuery(java.lang.String name, org.apache.lucene.search.Query query)booleanallowExpensiveQueries()BigArraysbigArrays()Return theBigArraysinstance for this node.org.apache.lucene.search.join.BitSetProducerbitsetFilter(org.apache.lucene.search.Query filter)MappedFieldTypebuildAnonymousFieldType(java.lang.String type)Given a type (eg.<FactoryType>
FactoryTypecompile(Script script, ScriptContext<FactoryType> context)Compile script using script servicebooleancontainsBrokenAnalysis(java.lang.String field)Does the index analyzer for this field have token filters that may produce backwards offsets in term vectorsQueryShardContextconvertToShardContext()Returns an instance ofQueryShardContextif available of null otherwisejava.util.Map<java.lang.String,org.apache.lucene.search.Query>copyNamedQueries()java.util.List<java.lang.String>defaultFields()DocumentMapperdocumentMapper(java.lang.String type)Returns sDocumentMapperinstance for the given type.voidexecuteAsyncActions(ActionListener listener)Executes all registered async actions and notifies the listener once it's done.protected voidfailIfFrozen()This method fails iffreezeContext()is called before on this context.voidfreezeContext()if this method is called the query context will throw exception if methods are accessed that could yield different results across executions likegetClient()ClientgetClient()MappedFieldTypegetFieldType(java.lang.String name)Returns theMappedFieldTypefor the provided field name.<IFD extends IndexFieldData<?>>
IFDgetForField(MappedFieldType fieldType)IndexgetFullyQualifiedIndex()Returns the fully qualified index including a remote cluster alias if applicable, and the index uuidorg.apache.lucene.analysis.AnalyzergetIndexAnalyzer(java.util.function.Function<java.lang.String,NamedAnalyzer> unindexedFieldAnalyzer)Return the index-time analyzer for the current indexIndexAnalyzersgetIndexAnalyzers()org.apache.lucene.index.IndexReadergetIndexReader()Return the currentIndexReader, ornullif no index reader is available, for instance if this rewrite context is used to index queries (percolation).IndexSettingsgetIndexSettings()Returns the index settings for this context.ObjectMappergetObjectMapper(java.lang.String name)org.apache.lucene.search.similarities.SimilaritygetSearchSimilarity()intgetShardId()Returns the shard ID this context was created for.java.lang.StringgetType()java.lang.String[]getTypes()ValuesSourceRegistrygetValuesSourceRegistry()booleanhasMappings()booleanhasNested()Indexindex()booleanindexMatches(java.lang.String pattern)Given an index pattern, checks whether it matches against the current shard.booleanindexSortedOnField(java.lang.String field)VersionindexVersionCreated()booleanisCacheable()Returnstrueiff the result of the processed search request is cacheable.booleanisFieldMapped(java.lang.String name)Returns true if the field identified by the provided name is mapped, false otherwisebooleanisMetadataField(java.lang.String field)booleanisSourceEnabled()SearchLookuplookup()Get the lookup to use during the search.MappingLookup.CacheKeymappingCacheKey()Cache key for current mapping.NestedScopenestedScope()longnowInMillis()Returns the time in milliseconds that is shared across all resources involved.ParsedDocumentparseDocument(SourceToParse source)Parse a document with current mapping.QueryBuilderparseInnerQueryBuilder(org.elasticsearch.common.xcontent.XContentParser parser)booleanqueryStringAllowLeadingWildcard()booleanqueryStringAnalyzeWildcard()booleanqueryStringLenient()java.util.Collection<java.lang.String>queryTypes()Returns the narrowed down explicit types, or, if not set, all types.voidregisterAsyncAction(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.org.apache.lucene.search.IndexSearchersearcher()Return the currentIndexSearcher, ornullif no index reader is available, for instance if this rewrite context is used to index queries (percolation).voidsetAllowUnmappedFields(boolean allowUnmappedFields)voidsetMapUnmappedFieldAsString(boolean mapUnmappedFieldAsString)voidsetTypes(java.lang.String... types)java.util.Set<java.lang.String>simpleMatchToIndexNames(java.lang.String pattern)Returns all the fields that match a given pattern.java.util.Set<java.lang.String>sourcePath(java.lang.String fullName)ParsedQuerytoQuery(QueryBuilder queryBuilder)Methods inherited from class org.elasticsearch.index.query.QueryRewriteContext
convertToCoordinatorRewriteContext, getWriteableRegistry, getXContentRegistry, hasAsyncActions
-
Constructor Details
-
QueryShardContext
public QueryShardContext(int shardId, IndexSettings indexSettings, BigArrays bigArrays, BitsetFilterCache bitsetFilterCache, TriFunction<MappedFieldType,java.lang.String,java.util.function.Supplier<SearchLookup>,IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService, MappingLookup mappingLookup, SimilarityService similarityService, ScriptService scriptService, org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, NamedWriteableRegistry namedWriteableRegistry, Client client, org.apache.lucene.search.IndexSearcher searcher, java.util.function.LongSupplier nowInMillis, java.lang.String clusterAlias, java.util.function.Predicate<java.lang.String> indexNameMatcher, java.util.function.BooleanSupplier allowExpensiveQueries, ValuesSourceRegistry valuesSourceRegistry, java.util.Map<java.lang.String,java.lang.Object> runtimeMappings)Build a QueryShardContext. -
QueryShardContext
-
-
Method Details
-
setTypes
public void setTypes(java.lang.String... types) -
getTypes
public java.lang.String[] getTypes() -
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) -
allowExpensiveQueries
public boolean allowExpensiveQueries() -
getForField
-
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() -
parseDocument
Parse a document with current mapping.- Throws:
MapperParsingException
-
hasNested
public boolean hasNested() -
hasMappings
public boolean hasMappings() -
simpleMatchToIndexNames
public java.util.Set<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. -
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:
setAllowUnmappedFields(boolean),setMapUnmappedFieldAsString(boolean)
-
isFieldMapped
public boolean isFieldMapped(java.lang.String name)Returns true if the field identified by the provided name is mapped, false otherwise -
getObjectMapper
-
isMetadataField
public boolean isMetadataField(java.lang.String field) -
sourcePath
public java.util.Set<java.lang.String> sourcePath(java.lang.String fullName) -
isSourceEnabled
public boolean isSourceEnabled() -
documentMapper
Returns sDocumentMapperinstance for the given type. Delegates toMapperService.documentMapper(String) -
buildAnonymousFieldType
Given a type (eg. long, string, ...), returns an anonymous field type that can be used for search operations. Generally used to handle unmapped fields in the context of sorting. -
getIndexAnalyzers
-
getIndexAnalyzer
public org.apache.lucene.analysis.Analyzer getIndexAnalyzer(java.util.function.Function<java.lang.String,NamedAnalyzer> unindexedFieldAnalyzer)Return the index-time analyzer for the current index- Parameters:
unindexedFieldAnalyzer- a function that builds an analyzer for unindexed fields
-
getValuesSourceRegistry
-
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. -
containsBrokenAnalysis
public boolean containsBrokenAnalysis(java.lang.String field)Does the index analyzer for this field have token filters that may produce backwards offsets in term vectors -
lookup
Get the lookup to use during the search. -
nestedScope
-
indexVersionCreated
-
indexMatches
public boolean indexMatches(java.lang.String pattern)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. -
indexSortedOnField
public boolean indexSortedOnField(java.lang.String field) -
toQuery
-
index
-
compile
Compile script using script service -
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:QueryRewriteContextRegisters 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:
registerAsyncActionin classQueryRewriteContext
-
executeAsyncActions
Description copied from class:QueryRewriteContextExecutes 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:
executeAsyncActionsin classQueryRewriteContext
-
isCacheable
public final boolean isCacheable()Returnstrueiff 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:QueryRewriteContextReturns the time in milliseconds that is shared across all resources involved. Even across shards and nodes.- Overrides:
nowInMillisin classQueryRewriteContext
-
getClient
-
parseInnerQueryBuilder
public QueryBuilder parseInnerQueryBuilder(org.elasticsearch.common.xcontent.XContentParser parser) throws java.io.IOException- Throws:
java.io.IOException
-
convertToShardContext
Description copied from class:QueryRewriteContextReturns an instance ofQueryShardContextif available of null otherwise- Overrides:
convertToShardContextin classQueryRewriteContext
-
getIndexSettings
Returns the index settings for this context. This might return null if the context has not index scope. -
getType
public java.lang.String getType() -
getIndexReader
public org.apache.lucene.index.IndexReader getIndexReader()Return the currentIndexReader, ornullif no index reader is available, for instance if this rewrite context is used to index queries (percolation). -
searcher
public org.apache.lucene.search.IndexSearcher searcher()Return the currentIndexSearcher, ornullif no index reader is available, for instance if this rewrite context is used to index queries (percolation). -
getFullyQualifiedIndex
Returns the fully qualified index including a remote cluster alias if applicable, and the index uuid -
bigArrays
Return theBigArraysinstance for this node. -
mappingCacheKey
Cache key for current mapping.
-