Class: OpenSearch::DSL::Search::Filters::Query

Inherits:
Object
  • Object
show all
Includes:
BaseComponent
Defined in:
lib/opensearch/dsl/search/filters/query.rb

Overview

A filter which wraps a query so it can be used as a filter

Examples:


search do
  query do
    filtered do
      filter do
        query do
          query_string :title do
            query 'Ruby OR Python'
          end
        end
      end
    end
  end
end

See Also:

Instance Method Summary collapse

Methods included from BaseComponent

included

Constructor Details

#initialize(*args, &block) ⇒ Query

Returns a new instance of Query.



55
56
57
58
59
60
61
# File 'lib/opensearch/dsl/search/filters/query.rb', line 55

def initialize(*args, &block)
  super
  if block
    @query = OpenSearch::DSL::Search::Query.new(*args, &block)
    @block = nil
  end
end

Instance Method Details

#to_hashHash

Converts the query definition to a Hash

Returns:

  • (Hash)


67
68
69
70
71
72
73
74
# File 'lib/opensearch/dsl/search/filters/query.rb', line 67

def to_hash
  hash = super
  if @query
    _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query
    hash[self.name].update(_query)
  end
  hash
end