module Springy

Constants

VERSION

Public Instance Methods

client() click to toggle source
# File lib/springy.rb, line 20
def client
  @client ||= Elasticsearch::Client.new
end
client=(client) click to toggle source
# File lib/springy.rb, line 24
def client=(client)
  @client = client
end
count_index(name, params = {}) click to toggle source
# File lib/springy.rb, line 53
def count_index(name, params = {})
  client.count({index: name}.merge(params))['count']
end
create_index(name, params = {}) click to toggle source
# File lib/springy.rb, line 45
def create_index(name, params = {})
  client.indices.create({index: name}.merge(params)) unless index_exists? name
end
delete_index(name) click to toggle source
# File lib/springy.rb, line 41
def delete_index(name)
  client.indices.delete(index: name) if index_exists? name
end
index_document(params = {}) click to toggle source
# File lib/springy.rb, line 57
def index_document(params = {})
  Utils.require_params!(:index_document, params, :index, :type, :body)

  raise IndexDoesNotExistError.new(
    "index #{params[:index]} does not exist"
  ) unless index_exists? params[:index]

  client.index(params)
end
index_exists?(name) click to toggle source
# File lib/springy.rb, line 37
def index_exists?(name)
  client.indices.exists? index: name
end
query(options = {}) click to toggle source
# File lib/springy.rb, line 67
def query(options = {})
  API.new(root: options)
end
refresh_index(name, params = {}) click to toggle source
# File lib/springy.rb, line 49
def refresh_index(name, params = {})
  client.indices.refresh({index: name}.merge(params)) if index_exists? name
end