Class SearchExecutionContext

java.lang.Object
org.elasticsearch.index.query.QueryRewriteContext
org.elasticsearch.index.query.SearchExecutionContext
Direct Known Subclasses:
FilteredSearchExecutionContext

public class SearchExecutionContext extends QueryRewriteContext
The context used to execute a search request on a shard. It provides access to required information like mapping definitions and document data. This context is used in several components of search execution, including building queries and fetching hits.
  • Constructor Details

  • Method Details

    • setAliasFilter

      public void setAliasFilter(QueryBuilder aliasFilter)
    • getAliasFilter

      public QueryBuilder getAliasFilter()
    • getSearchSimilarity

      public org.apache.lucene.search.similarities.Similarity getSearchSimilarity()
      The similarity to use in searches, which takes into account per-field configuration.
    • getDefaultSimilarity

      public org.apache.lucene.search.similarities.Similarity getDefaultSimilarity()
      The default similarity configured in the index settings.
    • defaultFields

      public List<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)
    • getForField

      public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType, MappedFieldType.FielddataOperation fielddataOperation)
    • addNamedQuery

      public void addNamedQuery(String name, org.apache.lucene.search.Query query)
    • copyNamedQueries

      public Map<String,org.apache.lucene.search.Query> copyNamedQueries()
    • hasNamedQueries

      public boolean hasNamedQueries()
    • parseDocument

      public ParsedDocument parseDocument(SourceToParse source) throws DocumentParsingException
      Parse a document with current mapping.
      Throws:
      DocumentParsingException
    • nestedLookup

      public NestedLookup nestedLookup()
    • hasMappings

      public boolean hasMappings()
    • isFieldMapped

      public boolean isFieldMapped(String name)
      Returns true if the field identified by the provided name is mapped, false otherwise
    • isMetadataField

      public boolean isMetadataField(String field)
    • isMultiField

      public boolean isMultiField(String field)
    • dimensionFields

      public Iterable<MappedFieldType> dimensionFields()
    • sourcePath

      public Set<String> sourcePath(String fullName)
    • parentPath

      public String parentPath(String field)
      If field is a leaf multi-field return the path to the parent field. Otherwise, return null.
    • isSourceEnabled

      public boolean isSourceEnabled()
      Will there be _source.
    • isSourceSynthetic

      public boolean isSourceSynthetic()
      Does the source need to be rebuilt on the fly?
    • newSourceLoader

      public SourceLoader newSourceLoader(boolean forceSyntheticSource)
      Build something to load source _source.
    • buildAnonymousFieldType

      public MappedFieldType buildAnonymousFieldType(String type)
      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.
    • getIndexAnalyzer

      public org.apache.lucene.analysis.Analyzer getIndexAnalyzer(Function<String,NamedAnalyzer> unindexedFieldAnalyzer)
      Return the index-time analyzer for the current index
      Parameters:
      unindexedFieldAnalyzer - a function that builds an analyzer for unindexed fields
    • setAllowedFields

      public void setAllowedFields(Predicate<String> allowedFields)
    • containsBrokenAnalysis

      public boolean containsBrokenAnalysis(String field)
      Does the index analyzer for this field have token filters that may produce backwards offsets in term vectors
    • lookup

      public SearchLookup lookup()
      Get the lookup to use during the search.
    • setLookupProviders

      public void setLookupProviders(SourceProvider sourceProvider, Function<org.apache.lucene.index.LeafReaderContext,LeafFieldLookupProvider> fieldLookupProvider)
      Replace the standard source provider and field lookup provider on the SearchLookup Note that this will replace the current SearchLookup with a new one, but will not update the source provider on previously build lookups. This method should only be called before IndexReader access by the current context
    • nestedScope

      public NestedScope nestedScope()
    • indexVersionCreated

      public IndexVersion indexVersionCreated()
    • indexSortedOnField

      public boolean indexSortedOnField(String field)
    • toQuery

      public ParsedQuery toQuery(QueryBuilder queryBuilder)
    • index

      public Index index()
    • compile

      public <FactoryType> FactoryType compile(Script script, ScriptContext<FactoryType> context)
      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 like getClient()
    • disableCache

      public void disableCache()
      Marks this context as not cacheable. This method fails if freezeContext() is called before on this context.
    • 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 rewriteable 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.
    • getShardRequestIndex

      public int getShardRequestIndex()
      Returns the shard request ordinal that is used by the main search request to reference this shard.
    • nowInMillis

      public long nowInMillis()
      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()
    • convertToSearchExecutionContext

      public final SearchExecutionContext convertToSearchExecutionContext()
      Description copied from class: QueryRewriteContext
      Returns an instance of SearchExecutionContext if available or null otherwise
      Overrides:
      convertToSearchExecutionContext in class QueryRewriteContext
    • getIndexReader

      public org.apache.lucene.index.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 org.apache.lucene.search.IndexSearcher searcher()
      Return the current IndexSearcher, or null if no index reader is available, which happens if this rewrite context is used to index queries (percolation).
    • requestSize

      public Integer requestSize()
    • fieldExistsInIndex

      public boolean fieldExistsInIndex(String fieldname)
      Is this field present in the underlying lucene index for the current shard?
    • mappingCacheKey

      public MappingLookup.CacheKey mappingCacheKey()
      Cache key for current mapping.
    • getNestedDocuments

      public NestedDocuments getNestedDocuments()
    • setRewriteToNamedQueries

      public void setRewriteToNamedQueries()
      Instructs to rewrite Elasticsearch queries with _name to Lucene NamedQuery
    • rewriteToNamedQuery

      public boolean rewriteToNamedQuery()
      Returns true if Elasticsearch queries with _name must be rewritten to Lucene NamedQuery
      Returns: