elastic_record 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/elastic_record.gemspec +1 -1
- data/lib/elastic_record/relation/batches.rb +34 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01876488cf87aafffd46c830a6712dd84f56c83d
|
4
|
+
data.tar.gz: 7db2399fa5d44bf81a3c157cd23c95d60b040c19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f8a6c431823345a68a2da9d2d6c6099f5449a240068c60aa1f3f6ccbd8d2d74bb95ef3ed2f4c6c4882c0a65c537b298adc0b42b7ecc979b04b82e6cf708181e
|
7
|
+
data.tar.gz: 032af52b81c1e79b7957934aa1812f809ef8109f18c418d95fd42dcfa70e99472dd28825b62020714d00aad35cc5f5945f95c7923e300d5e982db8c68c7298cc
|
data/elastic_record.gemspec
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
module ElasticRecord
|
2
2
|
class Relation
|
3
|
+
class ScanSearch
|
4
|
+
attr_reader :scroll_id
|
5
|
+
|
6
|
+
def initialize(model, scroll_id, options = {})
|
7
|
+
@model = model
|
8
|
+
@scroll_id = scroll_id
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def request_more_ids
|
13
|
+
json = @model.elastic_index.scroll(@scroll_id, keep_alive)
|
14
|
+
json['hits']['hits'].map { |hit| hit['_id'] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def keep_alive
|
18
|
+
@options[:keep_alive] || (raise "Must provide a :keep_alive option")
|
19
|
+
end
|
20
|
+
|
21
|
+
def requested_batch_size
|
22
|
+
@options[:batch_size]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
3
26
|
module Batches
|
4
27
|
def find_each(options = {})
|
5
28
|
find_in_batches(options) do |records|
|
@@ -14,24 +37,10 @@ module ElasticRecord
|
|
14
37
|
end
|
15
38
|
|
16
39
|
def find_ids_in_batches(options = {}, &block)
|
17
|
-
options
|
18
|
-
|
19
|
-
scroll_keep_alive = options[:keep_alive] || ElasticRecord::Config.scroll_keep_alive
|
20
|
-
size = options[:batch_size] || 100
|
21
|
-
|
22
|
-
options = {
|
23
|
-
scroll: scroll_keep_alive,
|
24
|
-
size: size,
|
25
|
-
search_type: 'scan'
|
26
|
-
}.update(options)
|
40
|
+
scan_search = create_scan_search(options)
|
27
41
|
|
28
|
-
|
29
|
-
|
30
|
-
hit_count = 0
|
31
|
-
|
32
|
-
while (hit_ids = get_scroll_hit_ids(scroll_id, scroll_keep_alive)).any?
|
33
|
-
hit_count += hit_ids.size
|
34
|
-
hit_ids.each_slice(size, &block)
|
42
|
+
while (hit_ids = scan_search.request_more_ids).any?
|
43
|
+
hit_ids.each_slice(scan_search.requested_batch_size, &block)
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
@@ -41,12 +50,15 @@ module ElasticRecord
|
|
41
50
|
end
|
42
51
|
end
|
43
52
|
|
44
|
-
|
53
|
+
def create_scan_search(options = {})
|
54
|
+
options[:batch_size] ||= 100
|
55
|
+
options[:keep_alive] ||= ElasticRecord::Config.scroll_keep_alive
|
45
56
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
search_options = {search_type: 'scan', size: options[:batch_size], scroll: options[:keep_alive]}
|
58
|
+
json = klass.elastic_index.search(as_elastic, search_options)
|
59
|
+
|
60
|
+
ElasticRecord::Relation::ScanSearch.new(klass, json['_scroll_id'], options)
|
61
|
+
end
|
50
62
|
end
|
51
63
|
end
|
52
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infogroup
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: arelastic
|