Class: Elastify::ElasticSearchHelper::Connector
- Inherits:
-
Object
- Object
- Elastify::ElasticSearchHelper::Connector
- Defined in:
- lib/elastify/elastic_search_helper.rb
Class Method Summary collapse
- .create(options, data) ⇒ Object
- .create_index(options) ⇒ Object
- .create_mapping(options) ⇒ Object
- .destroy(options, data) ⇒ Object
- .destroy_index(options) ⇒ Object
- .scroll(options, scroll_id, scroll_timer) ⇒ Object
- .search(options, dsl, scroll_timer) ⇒ Object
- .update(options, data) ⇒ Object
Class Method Details
.create(options, data) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/elastify/elastic_search_helper.rb', line 25 def self.create(, data) if data.blank? raise :elastify__create__required_data end if data[:id].blank? raise :elastify__create__required_data_id end url = "#{options[:base_url]}/#{options[:index]}/#{options[:type]}/#{data[:id]}" response = JSON.parse(RestClient.put(url, data.to_json, {})) end |
.create_index(options) ⇒ Object
73 74 75 76 |
# File 'lib/elastify/elastic_search_helper.rb', line 73 def self.create_index url = "#{options[:base_url]}/#{options[:index]}" response = JSON.parse(RestClient.put(url, {}.to_json, {})).to_hash end |
.create_mapping(options) ⇒ Object
81 82 83 84 85 |
# File 'lib/elastify/elastic_search_helper.rb', line 81 def self.create_mapping url = "#{options[:base_url]}/#{options[:index]}/_mappings/#{options[:type]}" puts [:map] response = JSON.parse(RestClient.put(url, [:map].squish, {})).to_hash end |
.destroy(options, data) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elastify/elastic_search_helper.rb', line 45 def self.destroy , data if data.blank? raise :elastify__delete__required_data end if data[:id].blank? raise :elastify__delete__required_data_id end url = "#{options[:base_url]}/#{options[:index]}/#{options[:type]}/#{data[:id]}" response = JSON.parse(RestClient.delete(url)).to_hash end |
.destroy_index(options) ⇒ Object
77 78 79 80 |
# File 'lib/elastify/elastic_search_helper.rb', line 77 def self.destroy_index url = "#{options[:base_url]}/#{options[:index]}" response = JSON.parse(RestClient.delete(url)).to_hash end |
.scroll(options, scroll_id, scroll_timer) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/elastify/elastic_search_helper.rb', line 64 def self.scroll , scroll_id, scroll_timer if scroll_id.blank? raise :elastify__search__required_scroll_id end url = "#{options[:base_url]}/_search/scroll" dsl = { scroll: scroll_timer, scroll_id: scroll_id } puts dsl.to_json response = SearchResultSet.new(RestClient.post(url, dsl.to_json, {})) end |
.search(options, dsl, scroll_timer) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/elastify/elastic_search_helper.rb', line 55 def self.search , dsl, scroll_timer if dsl.blank? raise :elastify__search__required_dsl end url = "#{options[:base_url]}/#{options[:index]}/#{options[:type]}/_search" url += "?scroll=#{scroll_timer}" if scroll_timer.present? puts url response = SearchResultSet.new(RestClient.post(url, dsl.to_json, {})) end |
.update(options, data) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/elastify/elastic_search_helper.rb', line 35 def self.update , data if data.blank? raise :elastify__update__required_data end if data[:id].blank? raise :elastify__update__required_data_id end url = "#{options[:base_url]}/#{options[:index]}/#{options[:type]}/#{data[:id]}" response = JSON.parse(RestClient.put(url, data.to_json, {})).to_hash end |