scalastic 0.2.0 → 0.3.0
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/.gitignore +1 -0
- data/README.md +23 -0
- data/lib/scalastic/partition.rb +16 -0
- data/lib/scalastic/version.rb +1 -1
- data/scalastic.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e03696369ef2695acb79cad272e8f6fedc263c37
|
4
|
+
data.tar.gz: 606aeeb6040d291368bf23fcb5ba0ee9fad63b6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37c76201da581d93675e0a792d8f5287ccf21ed7746a344e5b7959e0e6ca383eb5f4dc6a25b9270f34aa8f96bcb46949e97f444f9c4b38a64846236b8d022f59
|
7
|
+
data.tar.gz: f157f7cf2226f63a34fa13e711ad81df849370986fba6f3ef077bd041fa0288462c557357a6d34fd78b6c859225cfdc99098c912390a93e4c1056f68b01be275
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -196,6 +196,29 @@ count = partition.search(search_type: 'count')['hits']['total']
|
|
196
196
|
raise 'Some documents were not removed' unless count == 0
|
197
197
|
```
|
198
198
|
|
199
|
+
### Deleting by query
|
200
|
+
Scalastic partitions support delete_by_query, but because it is no longer available in Elasticsearch core, we use our own implementation which uses scan/scroll searches and bulk operations for deletion.
|
201
|
+
```ruby
|
202
|
+
client = Elasticsearch::Client.new
|
203
|
+
partitions = client.partitions
|
204
|
+
|
205
|
+
client.indices.create(index: 'delete_by_query')
|
206
|
+
partitions.prepare_index(index: 'delete_by_query')
|
207
|
+
|
208
|
+
p = partitions.create(index: 'delete_by_query', id: 1)
|
209
|
+
p.index(id: 1, type: 'test')
|
210
|
+
p.index(id: 2, type: 'test')
|
211
|
+
p.index(id: 3, type: 'test')
|
212
|
+
client.indices.flush(index: 'delete_by_query')
|
213
|
+
|
214
|
+
p.delete_by_query(body:{query:{terms:{_id: [1,3]}}})
|
215
|
+
client.indices.flush(index: 'delete_by_query')
|
216
|
+
|
217
|
+
expected_hits = [{'_index' => 'delete_by_query', '_type' => 'test', '_id' => '2', '_score' => 1.0, '_source' => {'scalastic_partition_id' => 1}}]
|
218
|
+
actual_hits = p.search['hits']['hits']
|
219
|
+
raise "Unexpected results!: #{actual_hits}" unless actual_hits == expected_hits
|
220
|
+
```
|
221
|
+
|
199
222
|
### Notes
|
200
223
|
* Indices must be *prepared* before they can be used by Scalastic by calling "prepare" on the partitions client; doing so will create critical field mappings. Each index must be prepared only once.
|
201
224
|
* All hash keys in arguments must be symbols; using anything else may result in unexpected behavior.
|
data/lib/scalastic/partition.rb
CHANGED
@@ -62,6 +62,18 @@ module Scalastic
|
|
62
62
|
es_client.bulk(args)
|
63
63
|
end
|
64
64
|
|
65
|
+
def delete_by_query(args)
|
66
|
+
args = args.merge(index: config.search_endpoint(id), search_type: 'scan', scroll: '1m', size: 500, fields: [])
|
67
|
+
results = es_client.search(args)
|
68
|
+
loop do
|
69
|
+
scroll_id = results['_scroll_id']
|
70
|
+
results = es_client.scroll(scroll_id: scroll_id, scroll: '1m')
|
71
|
+
ops = results['hits']['hits'].map{|h| delete_op(h)}
|
72
|
+
break if ops.empty?
|
73
|
+
es_client.bulk(body: ops)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
65
77
|
def inspect
|
66
78
|
"ES partition #{id}"
|
67
79
|
end
|
@@ -98,5 +110,9 @@ module Scalastic
|
|
98
110
|
end
|
99
111
|
entry
|
100
112
|
end
|
113
|
+
|
114
|
+
def delete_op(hit)
|
115
|
+
{delete: {_index: hit['_index'], _type: hit['_type'], _id: hit['_id']}}
|
116
|
+
end
|
101
117
|
end
|
102
118
|
end
|
data/lib/scalastic/version.rb
CHANGED
data/scalastic.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scalastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aliaksei Baturytski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: multi_json
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '1.0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '1.0'
|
97
83
|
description: Elasticsearch alias-based partitions for scalable indexing and searching
|
98
84
|
email:
|
99
85
|
- abaturytski@gmail.com
|