class ElasticsearchQueryParser::Grammar::Presenters::Query

Public Class Methods

new(terms, operator, nested_query) click to toggle source
# File elasticsearch_query_parser/grammar/presenters/query.rb, line 8
def initialize(terms, operator, nested_query)
  @terms = terms
  @operator = operator
  @nested_query = nested_query
end

Public Instance Methods

to_elasticsearch(include_bool_header = true) click to toggle source

If its `must_not` operator - just add `must_not` to root node and continue analyze nested queries Otherwise for nested query add new nested nodes

# File elasticsearch_query_parser/grammar/presenters/query.rb, line 16
def to_elasticsearch(include_bool_header = true)
  query = if operator.to_elasticsearch == :must_not
    result = nested_query[0].to_elasticsearch(false)
    result.merge(must_not: result.fetch(:must_not, []) + match_query(terms))
  else
    { operator.to_elasticsearch => match_query(terms + nested_query) }
  end
  include_bool_header ? { bool: query } : query
end