Class QueryShardContext


  • public class QueryShardContext
    extends QueryRewriteContext
    Context object used to create lucene queries on the shard level.
    • Method Detail

      • setTypes

        public void setTypes​(String... types)
      • getTypes

        public String[] getTypes()
      • getSearchSimilarity

        public Similarity getSearchSimilarity()
      • defaultFields

        public List<String> defaultFields()
      • queryStringLenient

        public boolean queryStringLenient()
      • queryStringAnalyzeWildcard

        public boolean queryStringAnalyzeWildcard()
      • queryStringAllowLeadingWildcard

        public boolean queryStringAllowLeadingWildcard()
      • addNamedQuery

        public void addNamedQuery​(String name,
                                  Query query)
      • simpleMatchToIndexNames

        public Set<String> simpleMatchToIndexNames​(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.
      • getSearchAnalyzer

        public 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 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 Collection<String> queryTypes()
        Returns the narrowed down explicit types, or, if not set, all types.
      • indexVersionCreated

        public Version indexVersionCreated()
      • indexMatches

        public boolean indexMatches​(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.
      • 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 like getClient()
      • failIfFrozen

        protected final void failIfFrozen()
        This method fails if freezeContext() 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​(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 class QueryRewriteContext
      • 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 always null. The list of registered actions is cleared once this method returns.
        Overrides:
        executeAsyncActions in class QueryRewriteContext
      • isCacheable

        public final boolean isCacheable()
        Returns true iff the result of the processed search request is cacheable. Otherwise false
      • 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 class QueryRewriteContext
      • getClient

        public Client getClient()
      • 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 IndexReader getIndexReader()
        Return the current IndexReader, or null if no index reader is available, for instance if this rewrite context is used to index queries (percolation).
      • searcher

        public IndexSearcher searcher()
        Return the current IndexSearcher, or null 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