Class: Elastify::Helpers::ElasticSearch::Connector
- Inherits:
-
Object
- Object
- Elastify::Helpers::ElasticSearch::Connector
- Defined in:
- lib/elastify/helpers/elastic_search/connector.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_timeout) ⇒ Object
- .search(options, dsl, scroll_timeout) ⇒ Object
- .update(options, data) ⇒ Object
Class Method Details
.create(options, data) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/elastify/helpers/elastic_search/connector.rb', line 6 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 = "#{[:base_url]}/#{[:index]}/#{[:type]}/#{data[:id]}" JSON.parse(RestClient.put(url, data.to_json, {})) end |
.create_index(options) ⇒ Object
56 57 58 59 |
# File 'lib/elastify/helpers/elastic_search/connector.rb', line 56 def self.create_index() url = "#{[:base_url]}/#{[:index]}" JSON.parse(RestClient.put(url, {}.to_json, {})).to_hash end |
.create_mapping(options) ⇒ Object
66 67 68 69 |
# File 'lib/elastify/helpers/elastic_search/connector.rb', line 66 def self.create_mapping() url = "#{[:base_url]}/#{[:index]}/_mappings/#{[:type]}" JSON.parse(RestClient.put(url, [:map].squish, {})).to_hash end |
.destroy(options, data) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/elastify/helpers/elastic_search/connector.rb', line 28 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 = "#{[:base_url]}/#{[:index]}/#{[:type]}/#{data[:id]}" JSON.parse(RestClient.delete(url)).to_hash end |
.destroy_index(options) ⇒ Object
61 62 63 64 |
# File 'lib/elastify/helpers/elastic_search/connector.rb', line 61 def self.destroy_index() url = "#{[:base_url]}/#{[:index]}" JSON.parse(RestClient.delete(url)).to_hash end |
.scroll(options, scroll_id, scroll_timeout) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/elastify/helpers/elastic_search/connector.rb', line 47 def self.scroll(, scroll_id, scroll_timeout) raise :elastify__search__required_scroll_id unless scroll_id.present? scroll_timeout ||= [:scroll_timeout] dsl = { scroll_id: scroll_id, scroll: scroll_timeout } client = elasticsearch_client response = client.scroll body: dsl Elastify::Helpers::ElasticSearch::SearchResultCollection.new(response, ) end |
.search(options, dsl, scroll_timeout) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/elastify/helpers/elastic_search/connector.rb', line 39 def self.search(, dsl, scroll_timeout) raise :elastify__search__required_dsl unless dsl.present? scroll_timeout ||= [:scroll_timeout] client = elasticsearch_client response = client.search body: dsl, index: [:index], type: [:type], scroll: scroll_timeout Elastify::Helpers::ElasticSearch::SearchResultCollection.new(response, ) end |
.update(options, data) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/elastify/helpers/elastic_search/connector.rb', line 17 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 = "#{[:base_url]}/#{[:index]}/#{[:type]}/#{data[:id]}" JSON.parse(RestClient.put(url, data.to_json, {})).to_hash end |