class Elastify::Helpers::ElasticSearch::Connector

Public Class Methods

create(options, data) click to toggle source
# File lib/elastify/helpers/elastic_search/connector.rb, line 6
def self.create(options, 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]}"
    JSON.parse(RestClient.put(url, data.to_json, {}))
end
create_index(options) click to toggle source
# File lib/elastify/helpers/elastic_search/connector.rb, line 56
def self.create_index(options)
    url = "#{options[:base_url]}/#{options[:index]}"
    JSON.parse(RestClient.put(url, {}.to_json, {})).to_hash
end
create_mapping(options) click to toggle source
# File lib/elastify/helpers/elastic_search/connector.rb, line 66
def self.create_mapping(options)
    url = "#{options[:base_url]}/#{options[:index]}/_mappings/#{options[:type]}"
    JSON.parse(RestClient.put(url, options[:map].squish, {})).to_hash
end
destroy(options, data) click to toggle source
# File lib/elastify/helpers/elastic_search/connector.rb, line 28
def self.destroy(options, 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]}"
    JSON.parse(RestClient.delete(url)).to_hash
end
destroy_index(options) click to toggle source
# File lib/elastify/helpers/elastic_search/connector.rb, line 61
def self.destroy_index(options)
    url = "#{options[:base_url]}/#{options[:index]}"
    JSON.parse(RestClient.delete(url)).to_hash
end
scroll(options, scroll_id, scroll_timeout) click to toggle source
# File lib/elastify/helpers/elastic_search/connector.rb, line 47
def self.scroll(options, scroll_id, scroll_timeout)
    raise :elastify__search__required_scroll_id unless scroll_id.present?
    scroll_timeout ||= options[:scroll_timeout]
    dsl = { scroll_id: scroll_id, scroll: scroll_timeout }
    client = elasticsearch_client options
    response = client.scroll body: dsl
    Elastify::Helpers::ElasticSearch::SearchResultCollection.new(response, options)
end
update(options, data) click to toggle source
# File lib/elastify/helpers/elastic_search/connector.rb, line 17
def self.update(options, 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]}"
    JSON.parse(RestClient.put(url, data.to_json, {})).to_hash
end

Private Class Methods

elasticsearch_client(options) click to toggle source
# File lib/elastify/helpers/elastic_search/connector.rb, line 72
def self.elasticsearch_client options
    Elasticsearch::Client.new host: options[:base_url]
end