Class: Elasticity::Search::Definition

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(index_name, document_type, body) ⇒ Definition

Returns a new instance of Definition.



13
14
15
16
17
# File 'lib/elasticity/search.rb', line 13

def initialize(index_name, document_type, body)
  @index_name    = index_name
  @document_type = document_type
  @body          = body
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



11
12
13
# File 'lib/elasticity/search.rb', line 11

def body
  @body
end

#document_typeObject

Returns the value of attribute document_type.



11
12
13
# File 'lib/elasticity/search.rb', line 11

def document_type
  @document_type
end

#index_nameObject

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_argsObject



23
24
25
# File 'lib/elasticity/search.rb', line 23

def to_count_args
  { index: @index_name, type: @document_type, body: { query: @body.fetch(:query) }}
end

#to_msearch_argsObject



31
32
33
# File 'lib/elasticity/search.rb', line 31

def to_msearch_args
  { index: @index_name, type: @document_type, search: @body }
end

#to_search_argsObject



27
28
29
# File 'lib/elasticity/search.rb', line 27

def to_search_args
  { index: @index_name, type: @document_type, body: @body }
end

#update(body_changes) ⇒ Object



19
20
21
# File 'lib/elasticity/search.rb', line 19

def update(body_changes)
  self.class.new(@index_name, @document_type, @body.deep_merge(body_changes))
end