scalastic 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd3dbca7672a601bba49bc18531c66f5d4427710
4
- data.tar.gz: 3669c3673f0ded567a2acec6993028195a3b2c44
3
+ metadata.gz: e03696369ef2695acb79cad272e8f6fedc263c37
4
+ data.tar.gz: 606aeeb6040d291368bf23fcb5ba0ee9fad63b6c
5
5
  SHA512:
6
- metadata.gz: d5ea03aa00e7513b8c33359480d1d3e49edeaf62e5408362ed4d156666adc4573dbb89872fa3824c838570407768f65ddd0dba52cf723621d969e6ad6602aeb3
7
- data.tar.gz: 46cfbf9227dc75f94e6e2ea0defa7979e8ddf55cd38f31817b047e043b979983badf578d10e098ed784f317186a8ea4162ee69e40f8a5b6743d7270a355d2b68
6
+ metadata.gz: 37c76201da581d93675e0a792d8f5287ccf21ed7746a344e5b7959e0e6ca383eb5f4dc6a25b9270f34aa8f96bcb46949e97f444f9c4b38a64846236b8d022f59
7
+ data.tar.gz: f157f7cf2226f63a34fa13e711ad81df849370986fba6f3ef077bd041fa0288462c557357a6d34fd78b6c859225cfdc99098c912390a93e4c1056f68b01be275
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /*.gem
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.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Scalastic
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/scalastic.gemspec CHANGED
@@ -25,5 +25,4 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "simplecov", "~> 0.11"
26
26
 
27
27
  spec.add_dependency "elasticsearch", "~> 1.0"
28
- spec.add_dependency "multi_json", "~> 1.0"
29
28
  end
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.2.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-01-18 00:00:00.000000000 Z
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