class Elasticsearch::Extensions::Documents::Storage

Attributes

client[R]
config[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/elasticsearch/extensions/documents/storage.rb, line 8
def initialize(options = {})
  @client = options.fetch(:client) { Documents.client }
  @config = options.fetch(:config) { Documents.configuration }
end

Public Instance Methods

create_index(index_name) click to toggle source
# File lib/elasticsearch/extensions/documents/storage.rb, line 21
def create_index(index_name)
  client.indices.create(index: index_name, body: index_definition) unless index_exists?(index_name)
end
drop_index(index_name) click to toggle source
# File lib/elasticsearch/extensions/documents/storage.rb, line 13
def drop_index(index_name)
  client.indices.delete(index: index_name) if index_exists?(index_name)
end
index_definition() click to toggle source
# File lib/elasticsearch/extensions/documents/storage.rb, line 25
def index_definition
  {}.tap do |body|
    body[:settings] = config.settings if config.settings
    body[:mappings] = config.mappings if config.mappings
  end
end
index_exists?(index_name) click to toggle source
# File lib/elasticsearch/extensions/documents/storage.rb, line 17
def index_exists?(index_name)
  client.indices.exists(index: index_name)
end