Class QueryRewriteContext

java.lang.Object
org.elasticsearch.index.query.QueryRewriteContext
Direct Known Subclasses:
CoordinatorRewriteContext, DataRewriteContext, InnerHitsRewriteContext, SearchExecutionContext

public class QueryRewriteContext extends Object
Context object used to rewrite QueryBuilder instances into simplified version.
  • Field Details

    • mapperService

      protected final MapperService mapperService
    • mappingLookup

      protected final MappingLookup mappingLookup
    • runtimeMappings

      protected final Map<String,MappedFieldType> runtimeMappings
    • indexSettings

      protected final IndexSettings indexSettings
    • fullyQualifiedIndex

      protected final Index fullyQualifiedIndex
    • indexNameMatcher

      protected final Predicate<String> indexNameMatcher
    • writeableRegistry

      protected final NamedWriteableRegistry writeableRegistry
    • valuesSourceRegistry

      protected final ValuesSourceRegistry valuesSourceRegistry
    • allowExpensiveQueries

      protected final BooleanSupplier allowExpensiveQueries
    • scriptService

      protected final ScriptCompiler scriptService
    • client

      protected final Client client
    • nowInMillis

      protected final LongSupplier nowInMillis
    • allowUnmappedFields

      protected boolean allowUnmappedFields
    • mapUnmappedFieldAsString

      protected boolean mapUnmappedFieldAsString
    • allowedFields

      protected Predicate<String> allowedFields
  • Constructor Details

  • Method Details

    • getParserConfig

      public XContentParserConfiguration getParserConfig()
      The registry used to build new XContentParsers. 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

      public SearchExecutionContext convertToSearchExecutionContext()
      Returns an instance of SearchExecutionContext if available or null otherwise
    • convertToCoordinatorRewriteContext

      public CoordinatorRewriteContext convertToCoordinatorRewriteContext()
      Returns an instance of CoordinatorRewriteContext if available or null otherwise
    • convertToIndexMetadataContext

      public QueryRewriteContext convertToIndexMetadataContext()
      Returns:
      an QueryRewriteContext instance that is aware of the mapping and other index metadata or null otherwise.
    • convertToDataRewriteContext

      public DataRewriteContext convertToDataRewriteContext()
      Returns an instance of DataRewriteContext if available or null otherwise
    • convertToInnerHitsRewriteContext

      public InnerHitsRewriteContext convertToInnerHitsRewriteContext()
    • getFieldType

      public MappedFieldType getFieldType(String name)
      Returns the MappedFieldType 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

      protected MappedFieldType fieldType(String name)
    • getIndexAnalyzers

      public IndexAnalyzers getIndexAnalyzers()
    • setAllowUnmappedFields

      public void setAllowUnmappedFields(boolean allowUnmappedFields)
    • setMapUnmappedFieldAsString

      public void setMapUnmappedFieldAsString(boolean mapUnmappedFieldAsString)
    • getWriteableRegistry

      public NamedWriteableRegistry getWriteableRegistry()
    • getValuesSourceRegistry

      public ValuesSourceRegistry getValuesSourceRegistry()
    • allowExpensiveQueries

      public boolean allowExpensiveQueries()
    • registerAsyncAction

      public void registerAsyncAction(BiConsumer<Client,ActionListener<?>> asyncAction)
      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()
      Returns true if there are any registered async actions.
    • executeAsyncActions

      public void executeAsyncActions(ActionListener listener)
      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.
    • getFullyQualifiedIndex

      public Index getFullyQualifiedIndex()
      Returns the fully qualified index including a remote cluster alias if applicable, and the index uuid
    • getIndexSettings

      public IndexSettings getIndexSettings()
      Returns the index settings for this context. This might return null if the context has not index scope.
    • getMappingLookup

      public MappingLookup getMappingLookup()
      Returns the MappingLookup for the queried index.
    • 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.
    • getMatchingFieldNames

      public Set<String> 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 to getFieldType(String)
      Parameters:
      pattern - the field name pattern
    • getAllFields

      public Iterable<Map.Entry<String,MappedFieldType>> getAllFields()
      Returns:
      An Iterable with key the field name and value the MappedFieldType