Class: Elasticord::Client::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticord/client/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elastic_search_client, entity, index, type) ⇒ Base

Returns a new instance of Base.



12
13
14
15
# File 'lib/elasticord/client/base.rb', line 12

def initialize(elastic_search_client, entity, index, type)
  @elastic_search_client, @entity, @index, @type =
    elastic_search_client, entity, index, type
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



17
18
19
# File 'lib/elasticord/client/base.rb', line 17

def index
  @index
end

#typeObject (readonly)

Returns the value of attribute type.



17
18
19
# File 'lib/elasticord/client/base.rb', line 17

def type
  @type
end

Instance Method Details

#create(attributes = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/elasticord/client/base.rb', line 19

def create(attributes = {})
  result = Client::Create.one \
    elastic_search_client, index, type, attributes

  return false unless result

  attributes[:id] ||= result['_id']

  entity.new(attributes)
end

#delete_allObject



46
47
48
# File 'lib/elasticord/client/base.rb', line 46

def delete_all
  Client::Delete.all(elastic_search_client, index)
end

#get(id) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/elasticord/client/base.rb', line 30

def get(id)
  result = Client::Get.one(elastic_search_client, index, type, id)

  return false unless result

  entity.new(result.merge({ 'id' => id }))
end

#noneObject



42
43
44
# File 'lib/elasticord/client/base.rb', line 42

def none
  Client::SearchBuilder.new(elastic_search_client, entity, index, type)
end

#refresh_indexObject



50
51
52
# File 'lib/elasticord/client/base.rb', line 50

def refresh_index
  Client::Index.refresh(elastic_search_client, index)
end

#search(body_params = {}) ⇒ Object



38
39
40
# File 'lib/elasticord/client/base.rb', line 38

def search(body_params = {})
  none.load(body_params)
end