Class: Elasticord::Client::Base
- Inherits:
-
Object
- Object
- Elasticord::Client::Base
- Defined in:
- lib/elasticord/client/base.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #create(attributes = {}) ⇒ Object
- #delete_all ⇒ Object
- #get(id) ⇒ Object
-
#initialize(elastic_search_client, entity, index, type) ⇒ Base
constructor
A new instance of Base.
- #none ⇒ Object
- #refresh_index ⇒ Object
- #search(body_params = {}) ⇒ Object
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
#index ⇒ Object (readonly)
Returns the value of attribute index.
17 18 19 |
# File 'lib/elasticord/client/base.rb', line 17 def index @index end |
#type ⇒ Object (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_all ⇒ Object
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 |
#none ⇒ Object
42 43 44 |
# File 'lib/elasticord/client/base.rb', line 42 def none Client::SearchBuilder.new(elastic_search_client, entity, index, type) end |
#refresh_index ⇒ Object
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 |