class AgnosticBackend::Elasticsearch::Index

Attributes

enable_all[R]
endpoint[R]
index_name[R]
type[R]

Public Instance Methods

client() click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 22
def client
  @client ||= AgnosticBackend::Elasticsearch::Client.new(endpoint: endpoint)
end
configure() click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 26
def configure
  body = mappings(indexer.flatten(schema))
  client.send_request(:put, path: "#{index_name}/_mapping/#{type}", body: body)
end
create() click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 31
def create
  client.send_request(:put, path: index_name)
end
destroy!() click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 35
def destroy!
  client.send_request(:delete, path: index_name)
end
exists?() click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 39
def exists?
  response = client.send_request(:head, path: index_name)
  response.success?
end
indexer() click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 10
def indexer
  AgnosticBackend::Elasticsearch::Indexer.new(self)
end
query_builder() click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 14
def query_builder
  AgnosticBackend::Queryable::Elasticsearch::QueryBuilder.new(self)
end
schema() click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 18
def schema
  @schema ||= @indexable_klass.schema { |ftype| ftype }
end

Private Instance Methods

index_fields(flat_schema) click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 53
def index_fields(flat_schema)
  flat_schema.map do |field_name, field_type|
    AgnosticBackend::Elasticsearch::IndexField.new(field_name, field_type)
  end
end
mappings(flat_schema) click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 46
def mappings(flat_schema)
  {
    "_all" => { "enabled" => enable_all },
    "properties" => index_fields(flat_schema).map{|field| field.definition}.reduce({}, &:merge)
  }
end
parse_options() click to toggle source
# File lib/agnostic_backend/elasticsearch/index.rb, line 59
def parse_options
  @index_name = parse_option(:index_name)
  @type = parse_option(:type)
  @endpoint = parse_option(:endpoint)
  @enable_all = parse_option(:enable_all, optional: true, default: false)
end