class Elasticsearch::Resources::Index
Public Class Methods
new(cluster:, &block)
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 12 def initialize(cluster:, &block) self.cluster = cluster configure(&block) end
types()
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 119 def self.types (@type_names ||= {}).collect do |key, type_name| [key, Object.const_get(type_name)] end.to_h end
Protected Class Methods
define_types(types = {})
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 127 def self.define_types(types = {}) @type_names = types.collect do |key, type| [key.to_sym, type.class == Class ? type.name : type] end.to_h end
Public Instance Methods
build_type(key:, type_class: nil)
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 48 def build_type(key:, type_class: nil) type_class = self.class.types[key] if type_class.nil? type_class&.new(index: self).tap do |type| settings.type(key).tap do |settings| type.settings = settings.dup unless settings.nil? end end end
client()
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 31 def client cluster.client end
count(body, options = {})
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 97 def count(body, options = {}) params = { body: body }.merge(options) query(:count, params) end
create()
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 77 def create query_index(:create) end
delete()
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 85 def delete query_index(:delete) end
exists?()
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 73 def exists? query_index(:exists?) end
find_cluster()
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 105 def find_cluster self.cluster end
find_index(index: nil)
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 109 def find_index(index: nil) matches_name?(index) ? self : nil end
find_type(index: nil, type:)
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 113 def find_type(index: nil, type:) types.find do |t| t.find_type(type: type) end end
name()
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 35 def name settings.name end
put_mapping(options = {})
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 81 def put_mapping(options = {}) query_index(:put_mapping, options) end
query(action, options = {})
click to toggle source
Calls superclass method
# File lib/elasticsearch/resources/index.rb, line 65 def query(action, options = {}) params = { index: name }.merge(options) super(action, **params) end
query_index(action, options = {})
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 57 def query_index(action, options = {}) params = { index: name }.merge(options) client.indices.send(action, **params) end
search(body, options = {})
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 89 def search(body, options = {}) params = { body: body }.merge(options) query(:search, params) end
setup!()
click to toggle source
Calls superclass method
# File lib/elasticsearch/resources/index.rb, line 17 def setup! unless exists? create super end end
teardown!()
click to toggle source
Calls superclass method
# File lib/elasticsearch/resources/index.rb, line 24 def teardown! if exists? delete super end end
types()
click to toggle source
# File lib/elasticsearch/resources/index.rb, line 39 def types @types ||= self.class.types.collect do |key, type_class| [ key, build_type(key: key) ] end.to_h end