Class: Elasticity::Search::Definition
- Inherits:
-
Object
- Object
- Elasticity::Search::Definition
- Defined in:
- lib/elasticity/search.rb
Overview
Elasticity::Search::Definition is a struct that encapsulates all the data specific to one Elasticsearch search.
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#document_types ⇒ Object
Returns the value of attribute document_types.
-
#index_name ⇒ Object
Returns the value of attribute index_name.
Instance Method Summary collapse
-
#initialize(index_name, document_types, body, search_args = {}) ⇒ Definition
constructor
A new instance of Definition.
- #to_count_args ⇒ Object
- #to_msearch_args ⇒ Object
- #to_search_args ⇒ Object
- #update(body_changes) ⇒ Object
Constructor Details
#initialize(index_name, document_types, body, search_args = {}) ⇒ Definition
Returns a new instance of Definition.
13 14 15 16 17 18 |
# File 'lib/elasticity/search.rb', line 13 def initialize(index_name, document_types, body, search_args = {}) @index_name = index_name @document_types = document_types @body = body.deep_symbolize_keys! @search_args = search_args end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
11 12 13 |
# File 'lib/elasticity/search.rb', line 11 def body @body end |
#document_types ⇒ Object
Returns the value of attribute document_types.
11 12 13 |
# File 'lib/elasticity/search.rb', line 11 def document_types @document_types end |
#index_name ⇒ Object
Returns the value of attribute index_name.
11 12 13 |
# File 'lib/elasticity/search.rb', line 11 def index_name @index_name end |
Instance Method Details
#to_count_args ⇒ Object
24 25 26 27 28 29 |
# File 'lib/elasticity/search.rb', line 24 def to_count_args { index: @index_name }.tap do |args| body = @body.slice(:query) args[:body] = body if body.present? end end |
#to_msearch_args ⇒ Object
35 36 37 38 39 |
# File 'lib/elasticity/search.rb', line 35 def to_msearch_args search_body = @search_args.merge(@body) { index: @index_name, search: search_body } end |
#to_search_args ⇒ Object
31 32 33 |
# File 'lib/elasticity/search.rb', line 31 def to_search_args @search_args.merge({ index: @index_name, body: @body }) end |
#update(body_changes) ⇒ Object
20 21 22 |
# File 'lib/elasticity/search.rb', line 20 def update(body_changes) self.class.new(@index_name, @document_types, @body.deep_merge(body_changes)) end |