Module: ElasticRecord::Index::Manage
- Included in:
- ElasticRecord::Index
- Defined in:
- lib/elastic_record/index/manage.rb
Instance Method Summary collapse
- #aliased_names ⇒ Object
- #all_names ⇒ Object
- #create(index_name = new_index_name, setting_overrides: {}) ⇒ Object
- #create_and_deploy(index_name = new_index_name) ⇒ Object
- #delete(index_name) ⇒ Object
- #delete_all ⇒ Object
- #deploy(index_name) ⇒ Object
- #exists?(index_name) ⇒ Boolean
- #refresh(index_name = alias_name) ⇒ Object
- #reset ⇒ Object
Instance Method Details
#aliased_names ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/elastic_record/index/manage.rb', line 65 def aliased_names if (index_names = all_names).any? json = connection.json_get "/#{index_names.join(',')}/_alias" json.keys.select do |index_name| json[index_name]['aliases'].keys.include?(alias_name) end else [] end end |
#all_names ⇒ Object
76 77 78 79 80 81 |
# File 'lib/elastic_record/index/manage.rb', line 76 def all_names connection.json_get("/#{alias_name}/_mapping").keys rescue # TODO: In ES 1.4, this returns empty rather than a 404 [] end |
#create(index_name = new_index_name, setting_overrides: {}) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/elastic_record/index/manage.rb', line 10 def create(index_name = new_index_name, setting_overrides: {}) connection.json_put "/#{index_name}", { "mappings" => { mapping_type => mapping }, "settings" => settings.merge(setting_overrides) } index_name end |
#create_and_deploy(index_name = new_index_name) ⇒ Object
4 5 6 7 8 |
# File 'lib/elastic_record/index/manage.rb', line 4 def create_and_deploy(index_name = new_index_name) create(index_name) deploy(index_name) index_name end |
#delete(index_name) ⇒ Object
20 21 22 |
# File 'lib/elastic_record/index/manage.rb', line 20 def delete(index_name) connection.json_delete "/#{index_name}" end |
#delete_all ⇒ Object
24 25 26 27 28 |
# File 'lib/elastic_record/index/manage.rb', line 24 def delete_all all_names.each do |index_name| delete index_name end end |
#deploy(index_name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elastic_record/index/manage.rb', line 34 def deploy(index_name) actions = [ { add: { "index" => index_name, "alias" => alias_name } } ] (aliased_names - [index_name]).each do |index_to_remove| actions << { remove: { "index" => index_to_remove, "alias" => alias_name } } end connection.json_post '/_aliases', actions: actions end |
#exists?(index_name) ⇒ Boolean
30 31 32 |
# File 'lib/elastic_record/index/manage.rb', line 30 def exists?(index_name) connection.head("/#{index_name}") == '200' end |
#refresh(index_name = alias_name) ⇒ Object
56 57 58 |
# File 'lib/elastic_record/index/manage.rb', line 56 def refresh(index_name = alias_name) connection.json_post "/#{index_name}/_refresh" end |
#reset ⇒ Object
60 61 62 63 |
# File 'lib/elastic_record/index/manage.rb', line 60 def reset delete_all create_and_deploy end |