es-elasticity 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +9 -0
- data/README.md +14 -1
- data/lib/elasticity/bulk.rb +12 -0
- data/lib/elasticity/index_mapper.rb +14 -0
- data/lib/elasticity/version.rb +1 -1
- data/spec/functional/persistence_spec.rb +28 -12
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81bec50770ad1681435091821100f72489c99522
|
4
|
+
data.tar.gz: e01e698ea9fd852b9a886063ae5072cfbc9ed930
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da2ddc9b326281ccef128a4a502cdfc8344cb3a5ddc01b2d8564ca29a7d34b5bfdbe652cc6102ef508c53e920e2176ef6c7df1afa82bb911584055b19c7100fd
|
7
|
+
data.tar.gz: f5cf61f522db5424dc54cea8ba20578ee3919ae18bc087d9eb2be1928968be619364fe264e4b8632d16525f02e42e247d50d11a341e672aedc2e55abd360675c
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
v0.5.1
|
2
|
+
- Add ability to reindex individual attributes of a document using the
|
3
|
+
bulk_update API.
|
4
|
+
v0.5.0
|
5
|
+
- Refactor of multisearch and search facade
|
6
|
+
- add Search::Results proxy object so pagination and meta data methods can
|
7
|
+
be standardize across all responses
|
8
|
+
- Searches no longer return a simple array, they now return the
|
9
|
+
Search::Results object which proxies array and is enumerable.
|
1
10
|
v0.4.5
|
2
11
|
- Fix issue with hash strings and pagination
|
3
12
|
v0.4.4
|
data/README.md
CHANGED
@@ -129,6 +129,19 @@ users = [
|
|
129
129
|
Search::User.bulk_index(users)
|
130
130
|
```
|
131
131
|
|
132
|
+
### Individual Attribute Indexing
|
133
|
+
|
134
|
+
If you you'd like to update a single attribute of the document instead of updating the entire document, you can use the `bulk_update` api.
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
document = [
|
138
|
+
{ _id: 1, attr_name: "attr_name", attr_vale: "attr_value" },
|
139
|
+
{ _id: 2, attr_name: "attr_name", attr_vale: "attr_value" }
|
140
|
+
]
|
141
|
+
|
142
|
+
Search::User.bulk_update(documents)
|
143
|
+
```
|
144
|
+
|
132
145
|
|
133
146
|
### Searching
|
134
147
|
|
@@ -244,7 +257,7 @@ This class on itself can't be queried or manipulated directly. Trying to call th
|
|
244
257
|
users = Search::User.segment("doximity.com")
|
245
258
|
users.create_index
|
246
259
|
|
247
|
-
# users is a dynamically defined class that inherits from the Search::User class,
|
260
|
+
# users is a dynamically defined class that inherits from the Search::User class,
|
248
261
|
# therefore having all the necessary methods defined just properly.
|
249
262
|
users # => Search::User{"doximity.com"}
|
250
263
|
users.class # => Class
|
data/lib/elasticity/bulk.rb
CHANGED
@@ -9,6 +9,10 @@ module Elasticity
|
|
9
9
|
@operations << { index: { _index: index_name, _type: type, _id: id, data: attributes }}
|
10
10
|
end
|
11
11
|
|
12
|
+
def update(index_name, type, id, attributes)
|
13
|
+
@operations << { update: { _index: index_name, _type: type, _id: id, data: attributes }}
|
14
|
+
end
|
15
|
+
|
12
16
|
def delete(index_name, type, id)
|
13
17
|
@operations << { delete: { _index: index_name, _type: type, _id: id }}
|
14
18
|
end
|
@@ -27,6 +31,10 @@ module Elasticity
|
|
27
31
|
super(@index_name, type, id, attributes)
|
28
32
|
end
|
29
33
|
|
34
|
+
def update(type, id, attributes)
|
35
|
+
super(@index_name, type, id, attributes)
|
36
|
+
end
|
37
|
+
|
30
38
|
def delete(type, id)
|
31
39
|
super(@index_name, type, id)
|
32
40
|
end
|
@@ -43,6 +51,10 @@ module Elasticity
|
|
43
51
|
super(@update_alias, type, id, attributes)
|
44
52
|
end
|
45
53
|
|
54
|
+
def update(type, id, attributes)
|
55
|
+
super(@update_alias, type, id, attributes)
|
56
|
+
end
|
57
|
+
|
46
58
|
def delete(type, id)
|
47
59
|
@delete_indexes.each do |index|
|
48
60
|
super(index, type, id)
|
@@ -17,6 +17,7 @@ module Elasticity
|
|
17
17
|
:delete,
|
18
18
|
:delete_by_search,
|
19
19
|
:bulk_index,
|
20
|
+
:bulk_update,
|
20
21
|
:bulk_delete,
|
21
22
|
:map_hit,
|
22
23
|
to: to
|
@@ -110,6 +111,19 @@ module Elasticity
|
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
114
|
+
# Bulk update the specicied attribute of the provided documents
|
115
|
+
def bulk_update(documents)
|
116
|
+
@strategy.bulk do |b|
|
117
|
+
documents.each do |doc|
|
118
|
+
b.update(
|
119
|
+
document_type,
|
120
|
+
doc[:_id],
|
121
|
+
{ doc: { doc[:attr_name] => doc[:attr_value] } }
|
122
|
+
)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
113
127
|
# Bulk delete documents matching provided ids
|
114
128
|
def bulk_delete(ids)
|
115
129
|
@strategy.bulk do |b|
|
data/lib/elasticity/version.rb
CHANGED
@@ -75,17 +75,19 @@ RSpec.describe "Persistence", elasticsearch: true do
|
|
75
75
|
c.strategy = Elasticity::Strategies::AliasIndex
|
76
76
|
|
77
77
|
c.mapping = {
|
78
|
+
_id: { path: "id" },
|
78
79
|
properties: {
|
80
|
+
id: { type: "integer" },
|
79
81
|
name: { type: "string" },
|
80
82
|
birthdate: { type: "date" },
|
81
83
|
},
|
82
84
|
}
|
83
85
|
end
|
84
86
|
|
85
|
-
attr_accessor :name, :birthdate
|
87
|
+
attr_accessor :id, :name, :birthdate
|
86
88
|
|
87
89
|
def to_document
|
88
|
-
{ name: name, birthdate: birthdate }
|
90
|
+
{ id: id, name: name, birthdate: birthdate }
|
89
91
|
end
|
90
92
|
end
|
91
93
|
end
|
@@ -104,8 +106,8 @@ RSpec.describe "Persistence", elasticsearch: true do
|
|
104
106
|
end
|
105
107
|
|
106
108
|
it "remaps to a different index transparently" do
|
107
|
-
john = subject.new(name: "John", birthdate: "1985-10-31")
|
108
|
-
mari = subject.new(name: "Mari", birthdate: "1986-09-24")
|
109
|
+
john = subject.new(id: 1, name: "John", birthdate: "1985-10-31")
|
110
|
+
mari = subject.new(id: 2, name: "Mari", birthdate: "1986-09-24")
|
109
111
|
|
110
112
|
john.update
|
111
113
|
mari.update
|
@@ -129,8 +131,9 @@ RSpec.describe "Persistence", elasticsearch: true do
|
|
129
131
|
end
|
130
132
|
|
131
133
|
it "handles in between state while remapping" do
|
132
|
-
|
133
|
-
|
134
|
+
number_of_docs = 2000
|
135
|
+
docs = number_of_docs.times.map do |i|
|
136
|
+
subject.new(id: i, name: "User #{i}", birthdate: "#{rand(20)+1980}-#{rand(11)+1}-#{rand(28)+1}").tap(&:update)
|
134
137
|
end
|
135
138
|
|
136
139
|
t = Thread.new { subject.remap! }
|
@@ -142,7 +145,7 @@ RSpec.describe "Persistence", elasticsearch: true do
|
|
142
145
|
to_delete.each(&:delete)
|
143
146
|
|
144
147
|
20.times.map do |i|
|
145
|
-
subject.new(name: "User #{i + docs.length}", birthdate: "#{rand(20)+1980}-#{rand(11)+1}-#{rand(28)+1}").tap(&:update)
|
148
|
+
subject.new(id: i + number_of_docs, name: "User #{i + docs.length}", birthdate: "#{rand(20)+1980}-#{rand(11)+1}-#{rand(28)+1}").tap(&:update)
|
146
149
|
end
|
147
150
|
|
148
151
|
t.join
|
@@ -153,8 +156,9 @@ RSpec.describe "Persistence", elasticsearch: true do
|
|
153
156
|
end
|
154
157
|
|
155
158
|
it "recover from remap interrupts" do
|
156
|
-
|
157
|
-
|
159
|
+
number_of_docs = 2000
|
160
|
+
docs = number_of_docs.times.map do |i|
|
161
|
+
subject.new(id: i, name: "User #{i}", birthdate: "#{rand(20)+1980}-#{rand(11)+1}-#{rand(28)+1}").tap(&:update)
|
158
162
|
end
|
159
163
|
|
160
164
|
t = Thread.new { subject.remap! }
|
@@ -166,7 +170,7 @@ RSpec.describe "Persistence", elasticsearch: true do
|
|
166
170
|
to_delete.each(&:delete)
|
167
171
|
|
168
172
|
20.times.map do |i|
|
169
|
-
subject.new(name: "User #{i + docs.length}", birthdate: "#{rand(20)+1980}-#{rand(11)+1}-#{rand(28)+1}").tap(&:update)
|
173
|
+
subject.new(id: i + number_of_docs, name: "User #{i + docs.length}", birthdate: "#{rand(20)+1980}-#{rand(11)+1}-#{rand(28)+1}").tap(&:update)
|
170
174
|
end
|
171
175
|
|
172
176
|
t.raise("Test Interrupt")
|
@@ -177,9 +181,9 @@ RSpec.describe "Persistence", elasticsearch: true do
|
|
177
181
|
expect(results.total).to eq(2010)
|
178
182
|
end
|
179
183
|
|
180
|
-
it "bulk indexes and delete" do
|
184
|
+
it "bulk indexes, updates and delete" do
|
181
185
|
docs = 2000.times.map do |i|
|
182
|
-
subject.new(name: "User #{i}", birthdate: "#{rand(20)+1980}-#{rand(11)+1}-#{rand(28)+1}").tap(&:update)
|
186
|
+
subject.new(id: i, name: "User #{i}", birthdate: "#{rand(20)+1980}-#{rand(11)+1}-#{rand(28)+1}").tap(&:update)
|
183
187
|
end
|
184
188
|
|
185
189
|
subject.bulk_index(docs)
|
@@ -188,6 +192,18 @@ RSpec.describe "Persistence", elasticsearch: true do
|
|
188
192
|
results = subject.search(from: 0, size: 3000)
|
189
193
|
expect(results.total).to eq 2000
|
190
194
|
|
195
|
+
docs = 2000.times.map do |i|
|
196
|
+
{ _id: i, attr_name: "name", attr_value: "Updated" }
|
197
|
+
end
|
198
|
+
|
199
|
+
subject.bulk_update(docs)
|
200
|
+
subject.flush_index
|
201
|
+
|
202
|
+
results = subject.search(from: 0, size: 3000)
|
203
|
+
expect(results.total).to eq 2000
|
204
|
+
|
205
|
+
expect(subject.search({ query: { match: { name: "Updated" } } } ).count).to eq(2000)
|
206
|
+
|
191
207
|
subject.bulk_delete(results.documents.map(&:_id))
|
192
208
|
subject.flush_index
|
193
209
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es-elasticity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Kochenburger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
230
|
version: '0'
|
231
231
|
requirements: []
|
232
232
|
rubyforge_project:
|
233
|
-
rubygems_version: 2.
|
233
|
+
rubygems_version: 2.2.2
|
234
234
|
signing_key:
|
235
235
|
specification_version: 4
|
236
236
|
summary: ActiveModel-based library for working with Elasticsearch
|
@@ -243,4 +243,3 @@ test_files:
|
|
243
243
|
- spec/units/multi_search_spec.rb
|
244
244
|
- spec/units/search_spec.rb
|
245
245
|
- spec/units/strategies/single_index_spec.rb
|
246
|
-
has_rdoc:
|