es-elasticity 0.13.5 → 1.0.0.jhumphreys
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/.circleci/config.yml +43 -42
- data/CHANGELOG.md +18 -0
- data/CONTRIBUTING.md +11 -12
- data/Gemfile.lock +53 -34
- data/README.md +48 -44
- data/es-elasticity.gemspec +7 -7
- data/lib/elasticity/base_document.rb +3 -1
- data/lib/elasticity/bulk.rb +20 -18
- data/lib/elasticity/config.rb +2 -0
- data/lib/elasticity/document.rb +2 -0
- data/lib/elasticity/index_config.rb +19 -5
- data/lib/elasticity/index_mapper.rb +10 -9
- data/lib/elasticity/instrumented_client.rb +2 -0
- data/lib/elasticity/log_subscriber.rb +2 -0
- data/lib/elasticity/multi_search.rb +2 -0
- data/lib/elasticity/multi_search_response_parser.rb +3 -0
- data/lib/elasticity/railtie.rb +3 -1
- data/lib/elasticity/search.rb +7 -5
- data/lib/elasticity/segmented_document.rb +2 -0
- data/lib/elasticity/strategies/alias_index.rb +32 -39
- data/lib/elasticity/strategies/single_index.rb +16 -20
- data/lib/elasticity/strategies.rb +2 -0
- data/lib/elasticity/version.rb +3 -1
- metadata +27 -22
- data/lib/elasticity/scrollable_search.rb +0 -15
data/lib/elasticity/bulk.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Elasticity
|
2
4
|
class Bulk
|
3
5
|
def initialize(client)
|
@@ -5,16 +7,16 @@ module Elasticity
|
|
5
7
|
@operations = []
|
6
8
|
end
|
7
9
|
|
8
|
-
def index(index_name,
|
9
|
-
@operations << { index: { _index: index_name,
|
10
|
+
def index(index_name, id, attributes)
|
11
|
+
@operations << { index: { _index: index_name, _id: id, data: attributes }}
|
10
12
|
end
|
11
13
|
|
12
|
-
def update(index_name,
|
13
|
-
@operations << { update: { _index: index_name,
|
14
|
+
def update(index_name, id, attributes)
|
15
|
+
@operations << { update: { _index: index_name, _id: id, data: attributes }}
|
14
16
|
end
|
15
17
|
|
16
|
-
def delete(index_name,
|
17
|
-
@operations << { delete: { _index: index_name,
|
18
|
+
def delete(index_name, id)
|
19
|
+
@operations << { delete: { _index: index_name, _id: id }}
|
18
20
|
end
|
19
21
|
|
20
22
|
def execute
|
@@ -27,16 +29,16 @@ module Elasticity
|
|
27
29
|
@index_name = index_name
|
28
30
|
end
|
29
31
|
|
30
|
-
def index(
|
31
|
-
super(@index_name,
|
32
|
+
def index(id, attributes)
|
33
|
+
super(@index_name, id, attributes)
|
32
34
|
end
|
33
35
|
|
34
|
-
def update(
|
35
|
-
super(@index_name,
|
36
|
+
def update(id, attributes)
|
37
|
+
super(@index_name, id, attributes)
|
36
38
|
end
|
37
39
|
|
38
|
-
def delete(
|
39
|
-
super(@index_name,
|
40
|
+
def delete(id)
|
41
|
+
super(@index_name, id)
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
@@ -47,17 +49,17 @@ module Elasticity
|
|
47
49
|
@delete_indexes = delete_indexes
|
48
50
|
end
|
49
51
|
|
50
|
-
def index(
|
51
|
-
super(@update_alias,
|
52
|
+
def index(id, attributes)
|
53
|
+
super(@update_alias, id, attributes)
|
52
54
|
end
|
53
55
|
|
54
|
-
def update(
|
55
|
-
super(@update_alias,
|
56
|
+
def update(id, attributes)
|
57
|
+
super(@update_alias, id, attributes)
|
56
58
|
end
|
57
59
|
|
58
|
-
def delete(
|
60
|
+
def delete(id)
|
59
61
|
@delete_indexes.each do |index|
|
60
|
-
super(index,
|
62
|
+
super(index, id)
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
data/lib/elasticity/config.rb
CHANGED
data/lib/elasticity/document.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Elasticity
|
2
4
|
class IndexConfig
|
3
5
|
class SubclassError < StandardError; end
|
4
6
|
|
5
|
-
SUBCLASSES_WARNING = "Indices created in Elasticsearch 6.0.0 or later may only contain a single mapping type. "
|
7
|
+
SUBCLASSES_WARNING = "Indices created in Elasticsearch 6.0.0 or later may only contain a single mapping type. "\
|
6
8
|
"Therefore, doument-type based inheritance has been disabled by Elasticity"
|
7
|
-
SUBCLASSES_ERROR = "Mapping types have been completely removed in Elasticsearch 7.0.0. "
|
9
|
+
SUBCLASSES_ERROR = "Mapping types have been completely removed in Elasticsearch 7.0.0. "\
|
8
10
|
"Therefore, doument-type based inheritance has been disabled by Elasticity"
|
9
|
-
VERSION_FOR_SUBCLASS_WARNING = "6.0.0"
|
10
|
-
VERSION_FOR_SUBCLASS_ERROR = "7.0.0"
|
11
|
+
VERSION_FOR_SUBCLASS_WARNING = "6.0.0"
|
12
|
+
VERSION_FOR_SUBCLASS_ERROR = "7.0.0"
|
11
13
|
ATTRS = [
|
12
14
|
:index_base_name, :document_type, :mapping, :strategy, :subclasses,
|
13
15
|
:settings, :use_new_timestamp_format, :include_type_name_on_create
|
14
16
|
].freeze
|
15
17
|
VALIDATABLE_ATTRS = [:index_base_name, :document_type, :strategy].freeze
|
18
|
+
DEPRECATED_ATTRS = [:use_new_timestamp_format, :include_type_name_on_create].freeze
|
16
19
|
|
17
20
|
attr_accessor(*ATTRS)
|
18
21
|
|
@@ -23,6 +26,7 @@ module Elasticity
|
|
23
26
|
@elasticity_config = elasticity_config
|
24
27
|
yield(self)
|
25
28
|
subclasses_warning_or_exception
|
29
|
+
warn_deprecated_config
|
26
30
|
validate!
|
27
31
|
end
|
28
32
|
|
@@ -38,9 +42,10 @@ module Elasticity
|
|
38
42
|
|
39
43
|
def definition
|
40
44
|
return @definition if defined?(@definition)
|
45
|
+
|
41
46
|
@definition = {
|
42
47
|
settings: merge_settings,
|
43
|
-
mappings:
|
48
|
+
mappings: @mapping.nil? ? {} : @mapping.deep_stringify_keys
|
44
49
|
}
|
45
50
|
subclasses.each do |doc_type, subclass|
|
46
51
|
@definition[:mappings][doc_type] = subclass.constantize.mapping
|
@@ -80,6 +85,15 @@ module Elasticity
|
|
80
85
|
@elasticity_config.settings.merge(settings || {})
|
81
86
|
end
|
82
87
|
|
88
|
+
def warn_deprecated_config
|
89
|
+
DEPRECATED_ATTRS.each do |attr|
|
90
|
+
ActiveSupport::Deprecation.warn(
|
91
|
+
"#{attr} is deprecated and will be "\
|
92
|
+
"removed in the next major release."
|
93
|
+
) if public_send(attr).present?
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
83
97
|
def subclasses_warning_or_exception
|
84
98
|
return if subclasses.nil? || subclasses.empty?
|
85
99
|
raise(SubclassError.new(SUBCLASSES_ERROR)) if es_version_meets_or_exceeds?(VERSION_FOR_SUBCLASS_ERROR)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Elasticity
|
2
4
|
class IndexMapper
|
3
5
|
def self.set_delegates(obj, to)
|
@@ -84,7 +86,7 @@ module Elasticity
|
|
84
86
|
|
85
87
|
# Index the given document
|
86
88
|
def index_document(id, document_hash)
|
87
|
-
@strategy.index_document(
|
89
|
+
@strategy.index_document(id, document_hash)
|
88
90
|
end
|
89
91
|
|
90
92
|
# Searches the index using the parameters provided in the body hash, following the same
|
@@ -99,25 +101,25 @@ module Elasticity
|
|
99
101
|
|
100
102
|
# Fetches one specific document from the index by ID.
|
101
103
|
def get(id)
|
102
|
-
doc = @strategy.get_document(
|
103
|
-
@document_klass.new(doc["_source"].merge(_id: doc[
|
104
|
+
doc = @strategy.get_document(id)
|
105
|
+
@document_klass.new(doc["_source"].merge(_id: doc["_id"])) if doc.present?
|
104
106
|
end
|
105
107
|
|
106
108
|
# Removes one specific document from the index.
|
107
109
|
def delete(id)
|
108
|
-
@strategy.delete_document(
|
110
|
+
@strategy.delete_document(id)
|
109
111
|
end
|
110
112
|
|
111
113
|
# Removes entries based on a search
|
112
114
|
def delete_by_search(search)
|
113
|
-
@strategy.delete_by_query(
|
115
|
+
@strategy.delete_by_query(search.body)
|
114
116
|
end
|
115
117
|
|
116
118
|
# Bulk index the provided documents
|
117
119
|
def bulk_index(documents)
|
118
120
|
@strategy.bulk do |b|
|
119
121
|
documents.each do |doc|
|
120
|
-
b.index(
|
122
|
+
b.index(doc._id, doc.to_document)
|
121
123
|
end
|
122
124
|
end
|
123
125
|
end
|
@@ -127,7 +129,6 @@ module Elasticity
|
|
127
129
|
@strategy.bulk do |b|
|
128
130
|
documents.each do |doc|
|
129
131
|
b.update(
|
130
|
-
document_type,
|
131
132
|
doc[:_id],
|
132
133
|
{ doc: { doc[:attr_name] => doc[:attr_value] } }
|
133
134
|
)
|
@@ -139,7 +140,7 @@ module Elasticity
|
|
139
140
|
def bulk_delete(ids)
|
140
141
|
@strategy.bulk do |b|
|
141
142
|
ids.each do |id|
|
142
|
-
b.delete(
|
143
|
+
b.delete(id)
|
143
144
|
end
|
144
145
|
end
|
145
146
|
end
|
@@ -156,7 +157,7 @@ module Elasticity
|
|
156
157
|
|
157
158
|
if hit["highlight"]
|
158
159
|
highlighted_attrs = hit["highlight"].each_with_object({}) do |(name, v), attrs|
|
159
|
-
name = name.gsub(/\..*\z/,
|
160
|
+
name = name.gsub(/\..*\z/, "")
|
160
161
|
|
161
162
|
attrs[name] ||= v
|
162
163
|
end
|
data/lib/elasticity/railtie.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "elasticity/log_subscriber"
|
2
4
|
|
3
5
|
module Elasticity
|
4
6
|
class Railtie < Rails::Railtie
|
5
|
-
initializer
|
7
|
+
initializer "elasticity.initialize_logging" do
|
6
8
|
LogSubscriber.attach_to(:elasticity)
|
7
9
|
end
|
8
10
|
end
|
data/lib/elasticity/search.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Elasticity
|
2
4
|
module Search
|
3
5
|
def self.build(client, index_name, document_types, body, search_args = {})
|
@@ -6,7 +8,7 @@ module Elasticity
|
|
6
8
|
end
|
7
9
|
|
8
10
|
# Elasticity::Search::Definition is a struct that encapsulates all the data specific to one
|
9
|
-
#
|
11
|
+
# Elasticsearch search.
|
10
12
|
class Definition
|
11
13
|
attr_accessor :index_name, :document_types, :body
|
12
14
|
|
@@ -22,20 +24,20 @@ module Elasticity
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def to_count_args
|
25
|
-
{ index: @index_name
|
27
|
+
{ index: @index_name }.tap do |args|
|
26
28
|
body = @body.slice(:query)
|
27
29
|
args[:body] = body if body.present?
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
def to_search_args
|
32
|
-
@search_args.merge({ index: @index_name,
|
34
|
+
@search_args.merge({ index: @index_name, body: @body })
|
33
35
|
end
|
34
36
|
|
35
37
|
def to_msearch_args
|
36
38
|
search_body = @search_args.merge(@body)
|
37
39
|
|
38
|
-
{ index: @index_name,
|
40
|
+
{ index: @index_name, search: search_body }
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -186,7 +188,7 @@ module Elasticity
|
|
186
188
|
def search
|
187
189
|
return @search if defined?(@search)
|
188
190
|
args = @search_definition.to_search_args
|
189
|
-
args = args.merge(search_type:
|
191
|
+
args = args.merge(search_type: :query_then_fetch, size: @size, scroll: @scroll)
|
190
192
|
@search = @client.search(args)
|
191
193
|
end
|
192
194
|
end
|
@@ -1,25 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Elasticity
|
2
4
|
module Strategies
|
3
5
|
# This strategy keeps two aliases that might be mapped to the same index or different index, allowing
|
4
6
|
# runtime changes by simply atomically updating the aliases. For example, look at the remap method
|
5
7
|
# implementation.
|
6
8
|
class AliasIndex
|
7
|
-
SNAPSHOT_ERROR_SNIPPET = "Cannot delete indices that are being snapshotted"
|
9
|
+
SNAPSHOT_ERROR_SNIPPET = "Cannot delete indices that are being snapshotted"
|
8
10
|
RETRYABLE_ERROR_SNIPPETS = [
|
9
11
|
SNAPSHOT_ERROR_SNIPPET
|
10
12
|
].freeze
|
11
13
|
|
12
14
|
STATUSES = [:missing, :ok]
|
13
15
|
|
14
|
-
def initialize(client, index_base_name, document_type, use_new_timestamp_format =
|
16
|
+
def initialize(client, index_base_name, document_type, use_new_timestamp_format = nil, include_type_name_on_create = nil)
|
15
17
|
@client = client
|
16
18
|
@main_alias = index_base_name
|
17
19
|
@update_alias = "#{index_base_name}_update"
|
18
20
|
@document_type = document_type
|
19
|
-
|
20
|
-
# included for compatibility with v7
|
21
|
-
@use_new_timestamp_format = use_new_timestamp_format
|
22
|
-
@include_type_name_on_create = include_type_name_on_create
|
23
21
|
end
|
24
22
|
|
25
23
|
def ref_index_name
|
@@ -60,23 +58,23 @@ module Elasticity
|
|
60
58
|
]
|
61
59
|
})
|
62
60
|
|
63
|
-
@client.
|
64
|
-
cursor = @client.search index: original_index, search_type:
|
61
|
+
@client.index_refresh(index: original_index)
|
62
|
+
cursor = @client.search index: original_index, search_type: :query_then_fetch, scroll: "10m", size: 100
|
65
63
|
loop do
|
66
|
-
hits = cursor[
|
64
|
+
hits = cursor["hits"]["hits"]
|
67
65
|
break if hits.empty?
|
68
66
|
|
69
67
|
# Fetch documents based on the ids that existed when the migration started, to make sure we only migrate
|
70
68
|
# documents that haven't been deleted.
|
71
69
|
id_docs = hits.map do |hit|
|
72
|
-
{ _index: original_index,
|
70
|
+
{ _index: original_index, _id: hit["_id"] }
|
73
71
|
end
|
74
72
|
|
75
73
|
docs = @client.mget(body: { docs: id_docs }, refresh: true)["docs"]
|
76
74
|
break if docs.empty?
|
77
75
|
|
78
76
|
# Modify document hashes to match the mapping definition so that legacy fields aren't added
|
79
|
-
defined_mapping_fields = index_def[:mappings][
|
77
|
+
defined_mapping_fields = index_def[:mappings]["properties"].keys
|
80
78
|
|
81
79
|
# Move only documents that still exists on the old index, into the new index.
|
82
80
|
ops = []
|
@@ -84,7 +82,7 @@ module Elasticity
|
|
84
82
|
if doc["found"]
|
85
83
|
legacy_fields = doc["_source"].keys - defined_mapping_fields
|
86
84
|
legacy_fields.each { |field| doc["_source"].delete(field) }
|
87
|
-
ops << { index: { _index: new_index,
|
85
|
+
ops << { index: { _index: new_index, _id: doc["_id"], data: doc["_source"] } }
|
88
86
|
end
|
89
87
|
end
|
90
88
|
|
@@ -94,12 +92,12 @@ module Elasticity
|
|
94
92
|
ops = []
|
95
93
|
@client.mget(body: { docs: id_docs }, refresh: true)["docs"].each_with_index do |new_doc, idx|
|
96
94
|
if docs[idx]["found"] && !new_doc["found"]
|
97
|
-
ops << { delete: { _index: new_index,
|
95
|
+
ops << { delete: { _index: new_index, _id: new_doc["_id"] } }
|
98
96
|
end
|
99
97
|
end
|
100
98
|
|
101
99
|
@client.bulk(body: ops) unless ops.empty?
|
102
|
-
cursor = @client.scroll(scroll_id: cursor[
|
100
|
+
cursor = @client.scroll(scroll_id: cursor["_scroll_id"], scroll: "1m", body: { scroll_id: cursor["_scroll_id"] })
|
103
101
|
end
|
104
102
|
|
105
103
|
# Update aliases to only point to the new index.
|
@@ -130,23 +128,23 @@ module Elasticity
|
|
130
128
|
]
|
131
129
|
})
|
132
130
|
|
133
|
-
@client.
|
134
|
-
cursor = @client.search index: new_index, search_type:
|
131
|
+
@client.index_refresh(index: new_index)
|
132
|
+
cursor = @client.search index: new_index, search_type: :query_then_fetch, scroll: "1m", size: 100
|
135
133
|
loop do
|
136
|
-
hits = cursor[
|
134
|
+
hits = cursor["hits"]["hits"]
|
137
135
|
break if hits.empty?
|
138
136
|
|
139
137
|
# Move all the documents that exists on the new index back to the old index
|
140
138
|
ops = []
|
141
139
|
hits.each do |doc|
|
142
|
-
ops << { index: { _index: original_index,
|
140
|
+
ops << { index: { _index: original_index, _id: doc["_id"], data: doc["_source"] } }
|
143
141
|
end
|
144
142
|
|
145
143
|
@client.bulk(body: ops)
|
146
|
-
cursor = @client.scroll(scroll_id: cursor[
|
144
|
+
cursor = @client.scroll(scroll_id: cursor["_scroll_id"], scroll: "1m")
|
147
145
|
end
|
148
146
|
|
149
|
-
@client.
|
147
|
+
@client.index_refresh(index: original_index)
|
150
148
|
@client.index_update_aliases(body: {
|
151
149
|
actions: [
|
152
150
|
{ remove: { index: new_index, alias: @main_alias } },
|
@@ -222,8 +220,8 @@ module Elasticity
|
|
222
220
|
create(index_def)
|
223
221
|
end
|
224
222
|
|
225
|
-
def index_document(
|
226
|
-
res = @client.index(index: @update_alias,
|
223
|
+
def index_document(id, attributes)
|
224
|
+
res = @client.index(index: @update_alias, id: id, body: attributes)
|
227
225
|
|
228
226
|
if id = res["_id"]
|
229
227
|
[id, res["_shards"] && res["_shards"]["successful"].to_i > 0]
|
@@ -232,24 +230,24 @@ module Elasticity
|
|
232
230
|
end
|
233
231
|
end
|
234
232
|
|
235
|
-
def delete_document(
|
233
|
+
def delete_document(id)
|
236
234
|
ops = (main_indexes | update_indexes).map do |index|
|
237
|
-
{ delete: { _index: index,
|
235
|
+
{ delete: { _index: index, _id: id } }
|
238
236
|
end
|
239
237
|
|
240
238
|
@client.bulk(body: ops)
|
241
239
|
end
|
242
240
|
|
243
|
-
def get_document(
|
244
|
-
@client.get(index: @main_alias,
|
241
|
+
def get_document(id)
|
242
|
+
@client.get(index: @main_alias, id: id)
|
245
243
|
end
|
246
244
|
|
247
245
|
def search_index
|
248
246
|
@main_alias
|
249
247
|
end
|
250
248
|
|
251
|
-
def delete_by_query(
|
252
|
-
@client.delete_by_query(index: @main_alias,
|
249
|
+
def delete_by_query(body)
|
250
|
+
@client.delete_by_query(index: @main_alias, body: body)
|
253
251
|
end
|
254
252
|
|
255
253
|
def bulk
|
@@ -267,21 +265,21 @@ module Elasticity
|
|
267
265
|
end
|
268
266
|
|
269
267
|
def settings
|
270
|
-
@client.index_get_settings(index: @main_alias
|
268
|
+
@client.index_get_settings(index: @main_alias).values.first
|
271
269
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
272
270
|
nil
|
273
271
|
end
|
274
272
|
|
275
273
|
def mappings
|
276
274
|
ActiveSupport::Deprecation.warn(
|
277
|
-
|
278
|
-
|
275
|
+
"Elasticity::Strategies::AliasIndex#mappings is deprecated, "\
|
276
|
+
"use mapping instead"
|
279
277
|
)
|
280
278
|
mapping
|
281
279
|
end
|
282
280
|
|
283
281
|
def mapping
|
284
|
-
@client.index_get_mapping(index: @main_alias
|
282
|
+
@client.index_get_mapping(index: @main_alias).values.first
|
285
283
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
286
284
|
nil
|
287
285
|
end
|
@@ -289,18 +287,13 @@ module Elasticity
|
|
289
287
|
private
|
290
288
|
|
291
289
|
def build_index_name
|
292
|
-
ts =
|
293
|
-
if @use_new_timestamp_format == true
|
294
|
-
ts = Time.now.utc.strftime("%Y%m%d%H%M%S%6N")
|
295
|
-
else
|
296
|
-
ts = Time.now.utc.strftime("%Y-%m-%d_%H:%M:%S.%6N")
|
297
|
-
end
|
290
|
+
ts = Time.now.utc.strftime("%Y%m%d%H%M%S%6N")
|
298
291
|
"#{@main_alias}-#{ts}"
|
299
292
|
end
|
300
293
|
|
301
294
|
def create_index(index_def)
|
302
295
|
name = build_index_name
|
303
|
-
@client.index_create(index: name, body: index_def
|
296
|
+
@client.index_create(index: name, body: index_def)
|
304
297
|
name
|
305
298
|
end
|
306
299
|
|
@@ -1,18 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Elasticity
|
2
4
|
module Strategies
|
3
5
|
class SingleIndex
|
4
6
|
STATUSES = [:missing, :ok]
|
5
7
|
|
6
|
-
def initialize(client, index_name, document_type, use_new_timestamp_format =
|
8
|
+
def initialize(client, index_name, document_type, use_new_timestamp_format = nil, include_type_name_on_create = nil)
|
7
9
|
@client = client
|
8
10
|
@index_name = index_name
|
9
11
|
@document_type = document_type
|
10
|
-
|
11
|
-
# included for compatibility with v7
|
12
|
-
@include_type_name_on_create = include_type_name_on_create
|
13
|
-
|
14
|
-
# not currently used. included for argument compatiblity with AliasStrategy
|
15
|
-
@use_new_timestamp_format = use_new_timestamp_format
|
16
12
|
end
|
17
13
|
|
18
14
|
def ref_index_name
|
@@ -29,7 +25,7 @@ module Elasticity
|
|
29
25
|
|
30
26
|
def create(index_def)
|
31
27
|
if missing?
|
32
|
-
@client.index_create(index: @index_name, body: index_def
|
28
|
+
@client.index_create(index: @index_name, body: index_def)
|
33
29
|
else
|
34
30
|
raise IndexError.new(@index_name, "index already exist")
|
35
31
|
end
|
@@ -52,8 +48,8 @@ module Elasticity
|
|
52
48
|
create(index_def)
|
53
49
|
end
|
54
50
|
|
55
|
-
def index_document(
|
56
|
-
res = @client.index(index: @index_name,
|
51
|
+
def index_document(id, attributes)
|
52
|
+
res = @client.index(index: @index_name, id: id, body: attributes)
|
57
53
|
|
58
54
|
if id = res["_id"]
|
59
55
|
[id, res["created"]]
|
@@ -62,20 +58,20 @@ module Elasticity
|
|
62
58
|
end
|
63
59
|
end
|
64
60
|
|
65
|
-
def delete_document(
|
66
|
-
@client.delete(index: @index_name,
|
61
|
+
def delete_document(id)
|
62
|
+
@client.delete(index: @index_name, id: id)
|
67
63
|
end
|
68
64
|
|
69
|
-
def get_document(
|
70
|
-
@client.get(index: @index_name,
|
65
|
+
def get_document(id)
|
66
|
+
@client.get(index: @index_name, id: id)
|
71
67
|
end
|
72
68
|
|
73
69
|
def search_index
|
74
70
|
@index_name
|
75
71
|
end
|
76
72
|
|
77
|
-
def delete_by_query(
|
78
|
-
@client.delete_by_query(index: @index_name,
|
73
|
+
def delete_by_query(body)
|
74
|
+
@client.delete_by_query(index: @index_name, body: body)
|
79
75
|
end
|
80
76
|
|
81
77
|
def bulk
|
@@ -85,21 +81,21 @@ module Elasticity
|
|
85
81
|
end
|
86
82
|
|
87
83
|
def settings
|
88
|
-
@client.index_get_settings(index: @index_name
|
84
|
+
@client.index_get_settings(index: @index_name).values.first
|
89
85
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
90
86
|
nil
|
91
87
|
end
|
92
88
|
|
93
89
|
def mappings
|
94
90
|
ActiveSupport::Deprecation.warn(
|
95
|
-
|
96
|
-
|
91
|
+
"Elasticity::Strategies::SingleIndex#mappings is deprecated, "\
|
92
|
+
"use mapping instead"
|
97
93
|
)
|
98
94
|
mapping
|
99
95
|
end
|
100
96
|
|
101
97
|
def mapping
|
102
|
-
@client.index_get_mapping(index: @index_name
|
98
|
+
@client.index_get_mapping(index: @index_name).values.first
|
103
99
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
104
100
|
nil
|
105
101
|
end
|
data/lib/elasticity/version.rb
CHANGED