Class: ElasticsearchQueryParser::Grammar::Presenters::Query
- Inherits:
-
Object
- Object
- ElasticsearchQueryParser::Grammar::Presenters::Query
- Defined in:
- lib/elasticsearch_query_parser/grammar/presenters/query.rb
Instance Method Summary collapse
-
#initialize(terms, operator, nested_query) ⇒ Query
constructor
A new instance of Query.
-
#to_elasticsearch(include_bool_header = true) ⇒ Object
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.
Constructor Details
#initialize(terms, operator, nested_query) ⇒ Query
Returns a new instance of Query.
8 9 10 11 12 |
# File 'lib/elasticsearch_query_parser/grammar/presenters/query.rb', line 8 def initialize(terms, operator, nested_query) @terms = terms @operator = operator @nested_query = nested_query end |
Instance Method Details
#to_elasticsearch(include_bool_header = true) ⇒ Object
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
16 17 18 19 20 21 22 23 24 |
# File 'lib/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 |