Class: Elasticated::Client
- Inherits:
-
Object
- Object
- Elasticated::Client
- Includes:
- Configurable
- Defined in:
- lib/elasticated/client.rb
Instance Attribute Summary collapse
-
#transport ⇒ Object
Returns the value of attribute transport.
Instance Method Summary collapse
- #count(body, opts = {}) ⇒ Object
- #create_alias(index_name, new_alias) ⇒ Object
- #create_index(index_name, opts = {}) ⇒ Object
- #delete(body, opts = {}) ⇒ Object
- #index_document(document_source, opts = {}) ⇒ Object
- #index_exists?(index_name) ⇒ Boolean
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #refresh ⇒ Object
- #refresh_index(index_name) ⇒ Object
- #remove_alias(index_name, index_alias) ⇒ Object
- #remove_aliases(index_name) ⇒ Object
- #scroll(scroll_id, opts = {}) ⇒ Object
- #search(body, opts = {}) ⇒ Object
- #update_document(document_source, opts = {}) ⇒ Object
Methods included from Configurable
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 |
# File 'lib/elasticated/client.rb', line 7 def initialize(opts={}) self.transport = ::Elasticsearch::Client.new opts end |
Instance Attribute Details
#transport ⇒ Object
Returns the value of attribute transport.
5 6 7 |
# File 'lib/elasticated/client.rb', line 5 def transport @transport end |
Instance Method Details
#count(body, opts = {}) ⇒ Object
63 64 65 66 |
# File 'lib/elasticated/client.rb', line 63 def count(body, opts={}) log.debug "Elasticsearch count #{body.to_json}" transport.count opts.merge body: body end |
#create_alias(index_name, new_alias) ⇒ Object
36 37 38 39 40 |
# File 'lib/elasticated/client.rb', line 36 def create_alias(index_name, new_alias) log.info "Putting alias #{new_alias} to index #{index_name}" transport.indices.put_alias index: index_name, name: new_alias log.info "Alias #{new_alias} for index #{index_name} created" end |
#create_index(index_name, opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/elasticated/client.rb', line 23 def create_index(index_name, opts={}) args = { index: index_name } shards = opts[:shards] mapping = opts[:mapping] body = Hash.new body.merge!(settings: { number_of_shards: shards }) if shards body.merge!(mappings: mapping) if mapping args.merge! body: body unless body.empty? log.info "Creating index #{index_name}" transport.indices.create args log.info "Index #{index_name} created" end |
#delete(body, opts = {}) ⇒ Object
78 79 80 81 |
# File 'lib/elasticated/client.rb', line 78 def delete(body, opts={}) log.debug "Elasticsearch delete #{body.to_json}" transport.delete_by_query opts.merge body: body end |
#index_document(document_source, opts = {}) ⇒ Object
11 12 13 |
# File 'lib/elasticated/client.rb', line 11 def index_document(document_source, opts={}) transport.index opts.merge body: document_source end |
#index_exists?(index_name) ⇒ Boolean
19 20 21 |
# File 'lib/elasticated/client.rb', line 19 def index_exists?(index_name) transport.indices.exists index: index_name end |
#refresh ⇒ Object
59 60 61 |
# File 'lib/elasticated/client.rb', line 59 def refresh transport.indices.refresh end |
#refresh_index(index_name) ⇒ Object
54 55 56 57 |
# File 'lib/elasticated/client.rb', line 54 def refresh_index(index_name) log.debug "Refreshing #{index_name}" transport.indices.refresh index: index_name end |
#remove_alias(index_name, index_alias) ⇒ Object
49 50 51 52 |
# File 'lib/elasticated/client.rb', line 49 def remove_alias(index_name, index_alias) log.info "Alias #{index_alias} removed from index #{index_name}" transport.indices.delete_alias index: index_name, name: index_alias end |
#remove_aliases(index_name) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/elasticated/client.rb', line 42 def remove_aliases(index_name) aliases = transport.indices.get_aliases[index_name]['aliases'].map(&:first) rescue Array.new aliases.each do |alias_name| transport.indices.delete_alias index: index_name, name: alias_name end end |
#scroll(scroll_id, opts = {}) ⇒ Object
73 74 75 76 |
# File 'lib/elasticated/client.rb', line 73 def scroll(scroll_id, opts={}) log.debug "Elasticsearch scroll #{scroll_id}" transport.scroll opts.merge scroll_id: scroll_id end |
#search(body, opts = {}) ⇒ Object
68 69 70 71 |
# File 'lib/elasticated/client.rb', line 68 def search(body, opts={}) log.debug "Elasticsearch query #{body.to_json}" transport.search opts.merge body: body end |
#update_document(document_source, opts = {}) ⇒ Object
15 16 17 |
# File 'lib/elasticated/client.rb', line 15 def update_document(document_source, opts={}) transport.update opts.merge body: { doc: document_source } end |