java.lang.Object
org.elasticsearch.xpack.esql.core.querydsl.query.Query
Direct Known Subclasses:
BoolQuery, ExistsQuery, GeoDistanceQuery, MatchAll, NotQuery, PrefixQuery, QueryStringQuery, RangeQuery, RegexQuery, TermQuery, TermsQuery, WildcardQuery

public abstract class Query extends Object
Intermediate representation of queries that is rewritten to fetch otherwise unreferenced nested fields and then used to build Elasticsearch QueryBuilders.

Our expression language spits out one of three values for any comparison, true, false, and null. Lucene's queries either match or don't match. They don't have a concept of null, at least not in the sense we need. The Lucene queries produced by asBuilder() produce queries that do not match documents who's comparison would return null. This is what we want in WHERE style operations. But when you need to negate the matches you need to make only false return values into matches - null returns should continue to not match. You can do that with the negate(org.elasticsearch.xpack.esql.core.tree.Source) method.

  • Field Details

  • Constructor Details

    • Query

      protected Query(Source source)
  • Method Details

    • source

      public Source source()
      Location in the source statement.
    • toQueryBuilder

      public final QueryBuilder toQueryBuilder()
      Convert to an Elasticsearch QueryBuilder all set up to execute the query. This ensures that queries have appropriate boosting for scoring.
    • asBuilder

      protected abstract QueryBuilder asBuilder()
      Used internally to convert to retrieve a QueryBuilder by queries.
    • innerToString

      protected abstract String innerToString()
      Used by toString() to produce a pretty string.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • negate

      public Query negate(Source source)
      Negate this query, returning a query that includes documents that would return false when running the represented operation. The default implementation just returns a NotQuery wrapping this because most queries don't model underlying operations that can return null. Queries that model expressions that can return null must make sure all documents that would return null are still excluded from the match.
    • scorable

      public boolean scorable()
      Defines whether a query should contribute to the overall score
    • unscore

      public static QueryBuilder unscore(QueryBuilder builder)
      Removes score from a query builder, so score is not affected by the query