class Elasticity::Strategies::SingleIndex

Constants

STATUSES

Public Class Methods

new(client, index_name, document_type, use_new_timestamp_format = false, include_type_name_on_create = true) click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 6
def initialize(client, index_name, document_type, use_new_timestamp_format = false, include_type_name_on_create = true)
  @client        = client
  @index_name    = index_name
  @document_type = document_type

  # included for compatibility with v7
  @include_type_name_on_create = include_type_name_on_create

  # not currently used. included for argument compatiblity with AliasStrategy
  @use_new_timestamp_format = use_new_timestamp_format
end

Public Instance Methods

bulk() { |b| ... } click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 81
def bulk
  b = Bulk::Index.new(@client, @index_name)
  yield b
  b.execute
end
create(index_def) click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 30
def create(index_def)
  if missing?
    @client.index_create(index: @index_name, body: index_def, include_type_name: @include_type_name_on_create)
  else
    raise IndexError.new(@index_name, "index already exist")
  end
end
create_if_undefined(index_def) click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 38
def create_if_undefined(index_def)
  create(index_def) if missing?
end
delete() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 42
def delete
  @client.index_delete(index: @index_name)
end
delete_by_query(type, body) click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 77
def delete_by_query(type, body)
  @client.delete_by_query(index: @index_name, type: type, body: body)
end
delete_document(type, id) click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 65
def delete_document(type, id)
  @client.delete(index: @index_name, type: type, id: id)
end
delete_if_defined() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 46
def delete_if_defined
  delete unless missing?
end
flush() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 107
def flush
  @client.index_flush(index: @index_name)
end
get_document(type, id) click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 69
def get_document(type, id)
  @client.get(index: @index_name, type: type, id: id)
end
index_document(type, id, attributes) click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 55
def index_document(type, id, attributes)
  res = @client.index(index: @index_name, type: type, id: id, body: attributes)

  if id = res["_id"]
    [id, res["created"]]
  else
    raise IndexError.new(@update_alias, "failed to index document. Response: #{res.inspect}")
  end
end
mapping() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 101
def mapping
  @client.index_get_mapping(index: @index_name, type: @document_type).values.first
rescue Elasticsearch::Transport::Transport::Errors::NotFound
  nil
end
mappings() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 93
def mappings
  ActiveSupport::Deprecation.warn(
    'Elasticity::Strategies::SingleIndex#mappings is deprecated, '\
    'use mapping instead'
  )
  mapping
end
missing?() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 26
def missing?
  not @client.index_exists(index: @index_name)
end
recreate(index_def) click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 50
def recreate(index_def)
  delete_if_defined
  create(index_def)
end
ref_index_name() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 18
def ref_index_name
  @index_name
end
refresh() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 111
def refresh
  @client.index_refresh(index: @index_name)
end
remap!() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 22
def remap!
  raise NotImplementedError
end
search_index() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 73
def search_index
  @index_name
end
settings() click to toggle source
# File lib/elasticity/strategies/single_index.rb, line 87
def settings
  @client.index_get_settings(index: @index_name, type: @document_type).values.first
rescue Elasticsearch::Transport::Transport::Errors::NotFound
  nil
end