esse 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/esse/backend/index/aliases.rb +8 -8
- data/lib/esse/backend/index/close.rb +3 -3
- data/lib/esse/backend/index/create.rb +4 -4
- data/lib/esse/backend/index/delete.rb +4 -4
- data/lib/esse/backend/index/documents.rb +253 -6
- data/lib/esse/backend/index/existance.rb +3 -3
- data/lib/esse/backend/index/open.rb +3 -3
- data/lib/esse/backend/index/refresh.rb +7 -5
- data/lib/esse/backend/index/reset.rb +4 -4
- data/lib/esse/backend/index/update.rb +7 -7
- data/lib/esse/backend/index.rb +16 -14
- data/lib/esse/backend/repository_backend.rb +105 -0
- data/lib/esse/cli/event_listener.rb +14 -0
- data/lib/esse/cli/generate.rb +53 -12
- data/lib/esse/cli/index/base_operation.rb +5 -13
- data/lib/esse/cli/index/import.rb +6 -2
- data/lib/esse/cli/index/update_mapping.rb +3 -4
- data/lib/esse/cli/index.rb +2 -0
- data/lib/esse/cli/templates/{type_collection.rb.erb → collection.rb.erb} +6 -18
- data/lib/esse/cli/templates/config.rb.erb +13 -3
- data/lib/esse/cli/templates/index.rb.erb +53 -109
- data/lib/esse/cli/templates/mappings.json +27 -0
- data/lib/esse/cli/templates/serializer.rb.erb +34 -0
- data/lib/esse/cli/templates/settings.json +62 -0
- data/lib/esse/client_proxy/search.rb +44 -0
- data/lib/esse/client_proxy.rb +32 -0
- data/lib/esse/cluster.rb +64 -9
- data/lib/esse/cluster_engine.rb +42 -0
- data/lib/esse/collection.rb +18 -0
- data/lib/esse/config.rb +14 -2
- data/lib/esse/core.rb +23 -6
- data/lib/esse/deprecations/cluster.rb +27 -0
- data/lib/esse/deprecations/index.rb +19 -0
- data/lib/esse/deprecations/repository.rb +19 -0
- data/lib/esse/deprecations.rb +3 -0
- data/lib/esse/dynamic_template.rb +39 -0
- data/lib/esse/errors.rb +53 -2
- data/lib/esse/events/event.rb +4 -19
- data/lib/esse/events.rb +3 -0
- data/lib/esse/hash_document.rb +38 -0
- data/lib/esse/import/bulk.rb +96 -0
- data/lib/esse/import/request_body.rb +60 -0
- data/lib/esse/index/attributes.rb +98 -0
- data/lib/esse/index/base.rb +1 -1
- data/lib/esse/index/inheritance.rb +30 -0
- data/lib/esse/index/mappings.rb +6 -19
- data/lib/esse/index/object_document_mapper.rb +95 -0
- data/lib/esse/index/plugins.rb +42 -0
- data/lib/esse/index/search.rb +27 -0
- data/lib/esse/index/settings.rb +2 -2
- data/lib/esse/index/type.rb +52 -11
- data/lib/esse/index.rb +10 -6
- data/lib/esse/index_mapping.rb +10 -2
- data/lib/esse/index_setting.rb +3 -1
- data/lib/esse/null_document.rb +35 -0
- data/lib/esse/plugins.rb +12 -0
- data/lib/esse/primitives/hstring.rb +1 -1
- data/lib/esse/{index_type → repository}/actions.rb +1 -1
- data/lib/esse/{index_type → repository}/backend.rb +2 -2
- data/lib/esse/repository/object_document_mapper.rb +157 -0
- data/lib/esse/repository.rb +18 -0
- data/lib/esse/search/query.rb +105 -0
- data/lib/esse/search/response.rb +46 -0
- data/lib/esse/serializer.rb +76 -0
- data/lib/esse/version.rb +1 -1
- data/lib/esse.rb +20 -5
- metadata +35 -30
- data/lib/esse/backend/index_type/documents.rb +0 -214
- data/lib/esse/backend/index_type.rb +0 -37
- data/lib/esse/cli/templates/type_mappings.json +0 -6
- data/lib/esse/cli/templates/type_serializer.rb.erb +0 -23
- data/lib/esse/index/naming.rb +0 -64
- data/lib/esse/index_type/mappings.rb +0 -42
- data/lib/esse/index_type.rb +0 -15
- data/lib/esse/object_document_mapper.rb +0 -110
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
class NullDocument < Esse::Serializer
|
5
|
+
def initialize
|
6
|
+
@object = nil
|
7
|
+
@options = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [NilClass] the document ID
|
11
|
+
def id
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [NilClass] the document type
|
16
|
+
def type
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [NilClass] the document routing
|
21
|
+
def routing
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [NilClass] the document meta
|
26
|
+
def meta
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [NilClass] the document source
|
31
|
+
def source
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/esse/plugins.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
module Plugins
|
5
|
+
def self.inherited_instance_variables(mod, hash)
|
6
|
+
mod.send(:define_method, :inherited_instance_variables) do
|
7
|
+
super().merge!(hash)
|
8
|
+
end
|
9
|
+
mod.send(:private, :inherited_instance_variables)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -9,7 +9,7 @@ module Esse
|
|
9
9
|
class Hstring
|
10
10
|
extend Forwardable
|
11
11
|
|
12
|
-
def_delegators :@value, :==, :eq, :to_s, :to_sym, :inspect, :sub, :capitalize
|
12
|
+
def_delegators :@value, :==, :eq, :to_s, :to_sym, :inspect, :sub, :capitalize, :tr
|
13
13
|
attr_reader :value
|
14
14
|
|
15
15
|
def self.def_conventional(bang_method, conv_method = nil)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Esse
|
4
|
-
class
|
4
|
+
class Repository
|
5
5
|
module ClassMethods
|
6
6
|
def elasticsearch
|
7
|
-
Esse::Backend::
|
7
|
+
Esse::Backend::RepositoryBackend.new(self)
|
8
8
|
end
|
9
9
|
alias_method :backend, :elasticsearch
|
10
10
|
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
# Delegates all the methods to the index ODM by prepending the type name.
|
5
|
+
#
|
6
|
+
# @see ObjectDocumentMapper
|
7
|
+
class Repository
|
8
|
+
module ClassMethods
|
9
|
+
# Convert ruby object to json. Arguments will be same of passed through the
|
10
|
+
# collection. It's allowed a block or a class with the `to_h` instance method.
|
11
|
+
# Example with block
|
12
|
+
# serializer do |model, **context|
|
13
|
+
# {
|
14
|
+
# id: model.id,
|
15
|
+
# admin: context[:is_admin],
|
16
|
+
# }
|
17
|
+
# end
|
18
|
+
# Example with serializer class
|
19
|
+
# serializer UserSerializer
|
20
|
+
def serializer(klass = nil, &block)
|
21
|
+
if @serializer_proc
|
22
|
+
raise ArgumentError, format('Serializer for %p already defined', repo_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
if block
|
26
|
+
@serializer_proc = ->(model, **kwargs) { coerce_to_document(block.call(model, **kwargs)) }
|
27
|
+
elsif klass.is_a?(Class) && klass <= Esse::Serializer
|
28
|
+
@serializer_proc = ->(model, **kwargs) { klass.new(model, **kwargs) }
|
29
|
+
elsif klass.is_a?(Class) && klass.instance_methods.include?(:to_h)
|
30
|
+
@serializer_proc = ->(model, **kwargs) { coerce_to_document(klass.new(model, **kwargs).to_h) }
|
31
|
+
elsif klass.is_a?(Class) && klass.instance_methods.include?(:as_json) # backward compatibility
|
32
|
+
@serializer_proc = ->(model, **kwargs) { coerce_to_document(klass.new(model, **kwargs).as_json) }
|
33
|
+
elsif klass.is_a?(Class) && klass.instance_methods.include?(:call)
|
34
|
+
@serializer_proc = ->(model, **kwargs) { coerce_to_document(klass.new(model, **kwargs).call) }
|
35
|
+
else
|
36
|
+
msg = format("%<arg>p is not a valid serializer. The serializer should inherit from Esse::Serializer or respond to `to_h'", arg: klass)
|
37
|
+
raise ArgumentError, msg
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def coerce_to_document(value)
|
42
|
+
case value
|
43
|
+
when Esse::Serializer
|
44
|
+
value
|
45
|
+
when Hash
|
46
|
+
Esse::HashDocument.new(value)
|
47
|
+
when NilClass, FalseClass
|
48
|
+
Esse::NullDocument.new
|
49
|
+
else
|
50
|
+
raise ArgumentError, format('%<arg>p is not a valid document. The document should be a hash or an instance of Esse::Serializer', arg: value)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Convert ruby object to json by using the serializer of the given document type.
|
55
|
+
# @param [Object] model The ruby object
|
56
|
+
# @param [Hash] kwargs The context
|
57
|
+
# @return [Esse::Document] The serialized document
|
58
|
+
def serialize(model, **kwargs)
|
59
|
+
if @serializer_proc.nil?
|
60
|
+
raise NotImplementedError, format('there is no %<t>p serializer defined for the %<k>p index', t: repo_name, k: index.to_s)
|
61
|
+
end
|
62
|
+
|
63
|
+
@serializer_proc.call(model, **kwargs)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Used to define the source of data. A block is required. And its
|
67
|
+
# content should yield an array of each object that should be serialized.
|
68
|
+
# The list of arguments will be passed throught the serializer method.
|
69
|
+
#
|
70
|
+
# Example:
|
71
|
+
# collection AdminStore
|
72
|
+
# collection do |**conditions, &block|
|
73
|
+
# User.where(conditions).find_in_batches(batch_size: 5000) do |batch|
|
74
|
+
# block.call(batch, conditions)
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
# @param [String] name The identification of the collection.
|
79
|
+
# @param [Class] klass The class of the collection. (Optional when block is passed)
|
80
|
+
# @param [Proc] block The block that will be used to iterate over the collection. (Optional when using a class)
|
81
|
+
# @return [void]
|
82
|
+
def collection(collection_klass = nil, **_, &block)
|
83
|
+
if collection_klass.nil? && block.nil?
|
84
|
+
raise ArgumentError, 'a document type, followed by a collection class or block that stream the data ' \
|
85
|
+
'is required to define the collection'
|
86
|
+
end
|
87
|
+
|
88
|
+
if block.nil? && collection_klass.is_a?(Class) && !collection_klass.include?(Enumerable)
|
89
|
+
msg = '%<arg>p is not a valid collection class.' \
|
90
|
+
' Collections should implement the Enumerable interface.'
|
91
|
+
raise ArgumentError, format(msg, arg: collection_klass)
|
92
|
+
end
|
93
|
+
|
94
|
+
@collection_proc = collection_klass || block
|
95
|
+
end
|
96
|
+
|
97
|
+
# Used to fetch all batch of data defined on the collection model.
|
98
|
+
# Arguments can be anything. They will just be passed through the block.
|
99
|
+
# Useful when the collection depends on scope or any other conditions
|
100
|
+
#
|
101
|
+
# Example:
|
102
|
+
# each_batch(active: true) do |data, **_collection_opts|
|
103
|
+
# puts data.size
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
# @todo Remove *args. It should only support keyword arguments
|
107
|
+
#
|
108
|
+
# @param [Hash] kwargs The context
|
109
|
+
# @param [Proc] block The block that will be used to iterate over the collection.
|
110
|
+
# @return [void]
|
111
|
+
def each_batch(*args, **kwargs, &block)
|
112
|
+
if @collection_proc.nil?
|
113
|
+
raise NotImplementedError, format('there is no %<t>p collection defined for the %<k>p index', t: repo_name, k: index.to_s)
|
114
|
+
end
|
115
|
+
|
116
|
+
case @collection_proc
|
117
|
+
when Class
|
118
|
+
@collection_proc.new(*args, **kwargs).each(&block)
|
119
|
+
else
|
120
|
+
@collection_proc.call(*args, **kwargs, &block)
|
121
|
+
end
|
122
|
+
rescue LocalJumpError
|
123
|
+
raise(SyntaxError, 'block must be explicitly declared in the collection definition')
|
124
|
+
end
|
125
|
+
|
126
|
+
# Wrap collection data into serialized batches
|
127
|
+
#
|
128
|
+
# @param [Hash] kwargs The context
|
129
|
+
# @return [Enumerator] The enumerator
|
130
|
+
# @yield [Array, **context] serialized collection and the optional context from the collection
|
131
|
+
def each_serialized_batch(**kwargs, &block)
|
132
|
+
each_batch(**kwargs) do |*args|
|
133
|
+
batch, collection_context = args
|
134
|
+
collection_context ||= {}
|
135
|
+
entries = [*batch].map { |entry| serialize(entry, **collection_context) }.compact
|
136
|
+
block.call(entries, **kwargs)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Wrap collection data into serialized documents
|
141
|
+
#
|
142
|
+
# Example:
|
143
|
+
# GeosIndex.documents(id: 1).first
|
144
|
+
#
|
145
|
+
# @return [Enumerator] All serialized entries
|
146
|
+
def documents(**kwargs)
|
147
|
+
Enumerator.new do |yielder|
|
148
|
+
each_serialized_batch(**kwargs) do |docs, **_collection_kargs|
|
149
|
+
docs.each { |document| yielder.yield(document) }
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
extend ClassMethods
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
# Type is actually deprecated. Elasticsearch today uses _doc instead of type
|
5
|
+
# And in upcoming release it will be totally removed.
|
6
|
+
# But I want to keep compatibility with old versions of es.
|
7
|
+
class Repository
|
8
|
+
class << self
|
9
|
+
# This methods will be defined using meta programming in the index respository definition
|
10
|
+
# @see Esse::Index::Type.repository
|
11
|
+
attr_reader :index
|
12
|
+
attr_accessor :document_type
|
13
|
+
end
|
14
|
+
require_relative 'repository/actions'
|
15
|
+
require_relative 'repository/backend'
|
16
|
+
require_relative 'repository/object_document_mapper'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
module Search
|
5
|
+
class Query
|
6
|
+
attr_reader :client_proxy, :definition
|
7
|
+
|
8
|
+
# @param client_proxy [Esse::ClientProxy] The client proxy to use for the query
|
9
|
+
# @param indices [<Array<Esse::Index, String>] The class of the index to search or the index name
|
10
|
+
# @param definition [Hash] The options to pass to the search.
|
11
|
+
def initialize(client_proxy, *indices, suffix: nil, **definition, &_block)
|
12
|
+
@client_proxy = client_proxy
|
13
|
+
@definition = definition
|
14
|
+
@definition[:index] = indices.map do |index|
|
15
|
+
if index.is_a?(Class) && index < Esse::Index
|
16
|
+
index.index_name(suffix: suffix)
|
17
|
+
elsif index.is_a?(String) || index.is_a?(Symbol)
|
18
|
+
[index, suffix].compact.join('_')
|
19
|
+
else
|
20
|
+
raise ArgumentError, format('Invalid index type: %<index>p. It should be a Esse::Index class or a String index name', index: index)
|
21
|
+
end
|
22
|
+
end.join(',')
|
23
|
+
end
|
24
|
+
|
25
|
+
def response
|
26
|
+
@response ||= execute_search_query!
|
27
|
+
end
|
28
|
+
|
29
|
+
def results
|
30
|
+
return paginated_results if respond_to?(:paginated_results, true)
|
31
|
+
|
32
|
+
response.hits
|
33
|
+
end
|
34
|
+
|
35
|
+
def scroll_hits(batch_size: 1_000, scroll: '1m')
|
36
|
+
response = execute_search_query!(size: batch_size, scroll: scroll)
|
37
|
+
scroll_id = nil
|
38
|
+
fetched = 0
|
39
|
+
total = response.total
|
40
|
+
|
41
|
+
loop do
|
42
|
+
fetched += response.hits.size
|
43
|
+
yield(response.hits) if response.hits.any?
|
44
|
+
break if fetched >= total
|
45
|
+
scroll_id = response.raw_response['scroll_id'] || response.raw_response['_scroll_id']
|
46
|
+
break unless scroll_id
|
47
|
+
response = execute_scroll_query(scroll: scroll, scroll_id: scroll_id)
|
48
|
+
end
|
49
|
+
ensure
|
50
|
+
begin
|
51
|
+
client_proxy.clear_scroll(body: {scroll_id: scroll_id}) if scroll_id
|
52
|
+
rescue Esse::Backend::NotFoundError
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def execute_search_query!(**execution_options)
|
59
|
+
resp, err = nil
|
60
|
+
Esse::Events.instrument('elasticsearch.execute_search_query') do |payload|
|
61
|
+
payload[:query] = self
|
62
|
+
begin
|
63
|
+
resp = Response.new(self, client_proxy.search(**definition, **execution_options))
|
64
|
+
rescue => e
|
65
|
+
err = e
|
66
|
+
end
|
67
|
+
payload[:error] = err if err
|
68
|
+
payload[:response] = resp
|
69
|
+
end
|
70
|
+
raise err if err
|
71
|
+
|
72
|
+
resp
|
73
|
+
end
|
74
|
+
|
75
|
+
def execute_scroll_query(scroll:, scroll_id:)
|
76
|
+
resp, err = nil
|
77
|
+
Esse::Events.instrument('elasticsearch.execute_search_query') do |payload|
|
78
|
+
payload[:query] = self
|
79
|
+
begin
|
80
|
+
resp = Response.new(self, client_proxy.scroll(scroll: scroll, body: { scroll_id: scroll_id }))
|
81
|
+
rescue => e
|
82
|
+
err = e
|
83
|
+
end
|
84
|
+
payload[:error] = err if err
|
85
|
+
payload[:response] = resp
|
86
|
+
end
|
87
|
+
raise err if err
|
88
|
+
|
89
|
+
resp
|
90
|
+
end
|
91
|
+
|
92
|
+
def reset!
|
93
|
+
@response = nil
|
94
|
+
end
|
95
|
+
|
96
|
+
def raw_limit_value
|
97
|
+
definition.dig(:body, :size) || definition.dig(:body, 'size') || definition.dig(:size) || definition.dig('size')
|
98
|
+
end
|
99
|
+
|
100
|
+
def raw_offset_value
|
101
|
+
definition.dig(:body, :from) || definition.dig(:body, 'from') || definition.dig(:from) || definition.dig('from')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
module Search
|
5
|
+
class Response
|
6
|
+
include Enumerable
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :hits, :each, :size, :empty?
|
10
|
+
attr_reader :query, :raw_response, :options
|
11
|
+
|
12
|
+
# @param [Esse::Search::Query] query The search query
|
13
|
+
# @param [Hash] raw_response The raw response from Elasticsearch
|
14
|
+
# @param [Hash] options The options passed to the search
|
15
|
+
def initialize(query, raw_response, **options)
|
16
|
+
@query = query
|
17
|
+
@raw_response = raw_response
|
18
|
+
@options = options
|
19
|
+
end
|
20
|
+
|
21
|
+
def shards
|
22
|
+
raw_response['_shards']
|
23
|
+
end
|
24
|
+
|
25
|
+
def aggregations
|
26
|
+
raw_response['aggregations']
|
27
|
+
end
|
28
|
+
|
29
|
+
def suggestions
|
30
|
+
raw_response['suggest']
|
31
|
+
end
|
32
|
+
|
33
|
+
def hits
|
34
|
+
raw_response.dig('hits', 'hits') || []
|
35
|
+
end
|
36
|
+
|
37
|
+
def total
|
38
|
+
if raw_response.dig('hits', 'total').respond_to?(:keys)
|
39
|
+
raw_response.dig('hits', 'total', 'value')
|
40
|
+
else
|
41
|
+
raw_response.dig('hits', 'total')
|
42
|
+
end.to_i
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esse
|
4
|
+
class Serializer
|
5
|
+
attr_reader :object, :options
|
6
|
+
|
7
|
+
def initialize(object, **options)
|
8
|
+
@object = object
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String, Number] the document ID
|
13
|
+
# @abstract Override this method to return the document ID
|
14
|
+
def id
|
15
|
+
raise NotImplementedError, 'Override this method to return the document ID'
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [String, nil] the document type
|
19
|
+
# @abstract Override this method to return the document type
|
20
|
+
def type
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String, nil] the document routing
|
25
|
+
# @abstract Override this method to return the document routing
|
26
|
+
def routing
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Hash] the document meta
|
31
|
+
# @abstract Override this method to return the document meta
|
32
|
+
def meta
|
33
|
+
{}
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Hash] the document source
|
37
|
+
# @abstract Override this method to return the document source
|
38
|
+
def source
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Hash] the document data
|
43
|
+
def to_h
|
44
|
+
source.merge(
|
45
|
+
_id: id,
|
46
|
+
).tap do |hash|
|
47
|
+
hash[:_type] = type if type
|
48
|
+
hash[:_routing] = routing if routing
|
49
|
+
hash.merge!(meta)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_bulk(data: true)
|
54
|
+
{ _id: id }.tap do |h|
|
55
|
+
h[:data] = source&.to_h if data
|
56
|
+
h[:_type] = type if type
|
57
|
+
h[:routing] = routing if routing
|
58
|
+
h.merge!(meta)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def ignore_on_index?
|
63
|
+
id.nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
def ignore_on_delete?
|
67
|
+
id.nil?
|
68
|
+
end
|
69
|
+
|
70
|
+
def ==(other)
|
71
|
+
other.is_a?(self.class) && (
|
72
|
+
id == other.id && type == other.type && routing == other.routing && meta == other.meta && source == other.source
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/esse/version.rb
CHANGED
data/lib/esse.rb
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require 'multi_json'
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'elasticsearch'
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'opensearch'
|
13
|
+
rescue LoadError
|
14
|
+
end
|
6
15
|
|
7
16
|
module Esse
|
8
|
-
SETTING_ROOT_KEY =
|
9
|
-
MAPPING_ROOT_KEY =
|
17
|
+
SETTING_ROOT_KEY = :settings
|
18
|
+
MAPPING_ROOT_KEY = :mappings
|
19
|
+
DEFAULT_REPO_NAME = 'default'
|
10
20
|
CLI_IGNORE_OPTS = %i[
|
11
21
|
require
|
12
22
|
silent
|
@@ -17,3 +27,8 @@ module Esse
|
|
17
27
|
config/initializers/esse.rb
|
18
28
|
].freeze
|
19
29
|
end
|
30
|
+
|
31
|
+
require_relative 'esse/plugins'
|
32
|
+
require_relative 'esse/core'
|
33
|
+
require_relative 'esse/errors'
|
34
|
+
require_relative 'esse/index'
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos G. Zimmermann
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exec
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: elasticsearch
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: multi_json
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -235,8 +221,7 @@ files:
|
|
235
221
|
- lib/esse/backend/index/refresh.rb
|
236
222
|
- lib/esse/backend/index/reset.rb
|
237
223
|
- lib/esse/backend/index/update.rb
|
238
|
-
- lib/esse/backend/
|
239
|
-
- lib/esse/backend/index_type/documents.rb
|
224
|
+
- lib/esse/backend/repository_backend.rb
|
240
225
|
- lib/esse/cli.rb
|
241
226
|
- lib/esse/cli/base.rb
|
242
227
|
- lib/esse/cli/event_listener.rb
|
@@ -252,41 +237,61 @@ files:
|
|
252
237
|
- lib/esse/cli/index/update_aliases.rb
|
253
238
|
- lib/esse/cli/index/update_mapping.rb
|
254
239
|
- lib/esse/cli/index/update_settings.rb
|
240
|
+
- lib/esse/cli/templates/collection.rb.erb
|
255
241
|
- lib/esse/cli/templates/config.rb.erb
|
256
242
|
- lib/esse/cli/templates/index.rb.erb
|
257
|
-
- lib/esse/cli/templates/
|
258
|
-
- lib/esse/cli/templates/
|
259
|
-
- lib/esse/cli/templates/
|
243
|
+
- lib/esse/cli/templates/mappings.json
|
244
|
+
- lib/esse/cli/templates/serializer.rb.erb
|
245
|
+
- lib/esse/cli/templates/settings.json
|
246
|
+
- lib/esse/client_proxy.rb
|
247
|
+
- lib/esse/client_proxy/search.rb
|
260
248
|
- lib/esse/cluster.rb
|
249
|
+
- lib/esse/cluster_engine.rb
|
250
|
+
- lib/esse/collection.rb
|
261
251
|
- lib/esse/config.rb
|
262
252
|
- lib/esse/core.rb
|
253
|
+
- lib/esse/deprecations.rb
|
254
|
+
- lib/esse/deprecations/cluster.rb
|
255
|
+
- lib/esse/deprecations/index.rb
|
256
|
+
- lib/esse/deprecations/repository.rb
|
257
|
+
- lib/esse/dynamic_template.rb
|
263
258
|
- lib/esse/errors.rb
|
264
259
|
- lib/esse/events.rb
|
265
260
|
- lib/esse/events/bus.rb
|
266
261
|
- lib/esse/events/event.rb
|
267
262
|
- lib/esse/events/publisher.rb
|
263
|
+
- lib/esse/hash_document.rb
|
264
|
+
- lib/esse/import/bulk.rb
|
265
|
+
- lib/esse/import/request_body.rb
|
268
266
|
- lib/esse/index.rb
|
269
267
|
- lib/esse/index/actions.rb
|
268
|
+
- lib/esse/index/attributes.rb
|
270
269
|
- lib/esse/index/backend.rb
|
271
270
|
- lib/esse/index/base.rb
|
272
271
|
- lib/esse/index/descendants.rb
|
273
272
|
- lib/esse/index/inheritance.rb
|
274
273
|
- lib/esse/index/mappings.rb
|
275
|
-
- lib/esse/index/
|
274
|
+
- lib/esse/index/object_document_mapper.rb
|
275
|
+
- lib/esse/index/plugins.rb
|
276
|
+
- lib/esse/index/search.rb
|
276
277
|
- lib/esse/index/settings.rb
|
277
278
|
- lib/esse/index/type.rb
|
278
279
|
- lib/esse/index_mapping.rb
|
279
280
|
- lib/esse/index_setting.rb
|
280
|
-
- lib/esse/index_type.rb
|
281
|
-
- lib/esse/index_type/actions.rb
|
282
|
-
- lib/esse/index_type/backend.rb
|
283
|
-
- lib/esse/index_type/mappings.rb
|
284
281
|
- lib/esse/logging.rb
|
285
|
-
- lib/esse/
|
282
|
+
- lib/esse/null_document.rb
|
283
|
+
- lib/esse/plugins.rb
|
286
284
|
- lib/esse/primitives.rb
|
287
285
|
- lib/esse/primitives/hash_utils.rb
|
288
286
|
- lib/esse/primitives/hstring.rb
|
289
287
|
- lib/esse/primitives/output.rb
|
288
|
+
- lib/esse/repository.rb
|
289
|
+
- lib/esse/repository/actions.rb
|
290
|
+
- lib/esse/repository/backend.rb
|
291
|
+
- lib/esse/repository/object_document_mapper.rb
|
292
|
+
- lib/esse/search/query.rb
|
293
|
+
- lib/esse/search/response.rb
|
294
|
+
- lib/esse/serializer.rb
|
290
295
|
- lib/esse/template_loader.rb
|
291
296
|
- lib/esse/version.rb
|
292
297
|
homepage: https://github.com/marcosgz/esse
|
@@ -296,7 +301,7 @@ metadata:
|
|
296
301
|
homepage_uri: https://github.com/marcosgz/esse
|
297
302
|
source_code_uri: https://github.com/marcosgz/esse
|
298
303
|
changelog_uri: https://github.com/marcosgz/esse/blob/master/CHANGELOG.md
|
299
|
-
post_install_message:
|
304
|
+
post_install_message:
|
300
305
|
rdoc_options: []
|
301
306
|
require_paths:
|
302
307
|
- lib
|
@@ -312,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
312
317
|
version: '0'
|
313
318
|
requirements: []
|
314
319
|
rubygems_version: 3.0.3.1
|
315
|
-
signing_key:
|
320
|
+
signing_key:
|
316
321
|
specification_version: 4
|
317
322
|
summary: Pure Ruby toolkit based on official elasticsearch-ruby library. (No! It isn't
|
318
323
|
a new DSL)
|