search_flip 2.0.0.beta4 → 2.0.0.beta5
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/README.md +1 -1
- data/lib/search_flip/bulk.rb +23 -14
- data/lib/search_flip/config.rb +1 -0
- data/lib/search_flip/connection.rb +9 -6
- data/lib/search_flip/index.rb +6 -2
- data/lib/search_flip/version.rb +1 -1
- data/spec/search_flip/bulk_spec.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0d1ed2d2431d99cbe9949cb24154bfda3c2188713eb7432a6a8f1c6d5e45fe8
|
4
|
+
data.tar.gz: fbb8f6f7989552d6944a3d238ab3ca22c5ff2ca2c2c3ca7dddf1a3d8c4825ecc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f72caff2b7806d19d88d31ea8900fa739d10975d121d83245e7111552cbfc95fda81dde504f8b235ed4fdc6a9a6a3056029c404a638045d86a6c9fc606a23fd
|
7
|
+
data.tar.gz: ea91ff174b46ad96bb29a94a9173ba9295ec503e731abc6e0956b1788dd73197aebc75c43eb302f59c6554822c5ebf2c7dee6006878462137ad1e57b1c512dad
|
data/README.md
CHANGED
data/lib/search_flip/bulk.rb
CHANGED
@@ -14,7 +14,7 @@ module SearchFlip
|
|
14
14
|
class Bulk
|
15
15
|
class Error < StandardError; end
|
16
16
|
|
17
|
-
|
17
|
+
attr_reader :url, :options, :ignore_errors
|
18
18
|
|
19
19
|
# Builds and yields a new Bulk object, ie initiates the buffer, yields,
|
20
20
|
# sends batches of records each time the buffer is full, and sends a final
|
@@ -32,8 +32,9 @@ module SearchFlip
|
|
32
32
|
# end
|
33
33
|
#
|
34
34
|
# @param url [String] The endpoint to send bulk requests to
|
35
|
-
# @param count [Fixnum] The maximum number of documents per bulk request
|
36
35
|
# @param options [Hash] Options for the bulk requests
|
36
|
+
# @option options batch_size [Fixnum] The maximum number of documents per bulk
|
37
|
+
# request
|
37
38
|
# @option options ignore_errors [Array, Fixnum] Errors that should be
|
38
39
|
# ignored. If you eg want to ignore errors resulting from conflicts,
|
39
40
|
# you can specify to ignore 409 here.
|
@@ -43,12 +44,16 @@ module SearchFlip
|
|
43
44
|
# @option options http_client [SearchFlip::HTTPClient] An optional http
|
44
45
|
# client instance
|
45
46
|
|
46
|
-
def initialize(url,
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
def initialize(url, options = {})
|
48
|
+
@url = url
|
49
|
+
@options = options
|
50
|
+
@http_client = options[:http_client] || SearchFlip::HTTPClient.new
|
51
|
+
@ignore_errors = Array(options[:ignore_errors]).to_set if options[:ignore_errors]
|
52
|
+
|
53
|
+
@bulk_limit = options[:bulk_limit] || SearchFlip::Config[:bulk_limit]
|
54
|
+
@bulk_max_mb = options[:bulk_max_mb] || SearchFlip::Config[:bulk_max_mb]
|
55
|
+
|
56
|
+
@bulk_max_bytes = @bulk_max_mb * 1024 * 1024
|
52
57
|
|
53
58
|
init
|
54
59
|
|
@@ -117,7 +122,7 @@ module SearchFlip
|
|
117
122
|
|
118
123
|
def upload
|
119
124
|
response =
|
120
|
-
http_client
|
125
|
+
@http_client
|
121
126
|
.headers(accept: "application/json", content_type: "application/x-ndjson")
|
122
127
|
.put(url, body: @payload, params: ignore_errors ? {} : { filter_path: "errors" })
|
123
128
|
|
@@ -141,17 +146,21 @@ module SearchFlip
|
|
141
146
|
end
|
142
147
|
|
143
148
|
def perform(action, id, json = nil, options = {})
|
144
|
-
|
145
|
-
|
149
|
+
new_payload = SearchFlip::JSON.generate(action => options.merge(_id: id))
|
150
|
+
new_payload << "\n"
|
146
151
|
|
147
152
|
if json
|
148
|
-
|
149
|
-
|
153
|
+
new_payload << json
|
154
|
+
new_payload << "\n"
|
150
155
|
end
|
151
156
|
|
157
|
+
upload if @num > 0 && @payload.bytesize + new_payload.bytesize >= @bulk_max_bytes
|
158
|
+
|
159
|
+
@payload << new_payload
|
160
|
+
|
152
161
|
@num += 1
|
153
162
|
|
154
|
-
upload if @num >=
|
163
|
+
upload if @num >= @bulk_limit || @payload.bytesize >= @bulk_max_bytes
|
155
164
|
end
|
156
165
|
end
|
157
166
|
end
|
data/lib/search_flip/config.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
|
2
2
|
module SearchFlip
|
3
3
|
class Connection
|
4
|
-
attr_reader :base_url, :http_client
|
4
|
+
attr_reader :base_url, :http_client, :bulk_limit, :bulk_max_mb
|
5
5
|
|
6
6
|
# Creates a new connection.
|
7
7
|
#
|
8
8
|
# @example
|
9
9
|
# SearchFlip::Connection.new(base_url: "http://elasticsearch.host:9200")
|
10
10
|
#
|
11
|
-
# @param
|
12
|
-
# @
|
11
|
+
# @param options [Hash] A hash containing the config options
|
12
|
+
# @option options base_url [String] The base url for the connection
|
13
|
+
# @option options http_client [SearchFlip::HTTPClient] An optional http client instance
|
14
|
+
# @option options bulk_max_mb [Fixnum] An optional MB limit for bulk requests
|
13
15
|
|
14
|
-
def initialize(
|
15
|
-
@base_url = base_url
|
16
|
-
@http_client = http_client
|
16
|
+
def initialize(options = {})
|
17
|
+
@base_url = options[:base_url] || SearchFlip::Config[:base_url]
|
18
|
+
@http_client = options[:http_client] || SearchFlip::HTTPClient.new
|
19
|
+
@bulk_limit = options[:bulk_limit] || SearchFlip::Config[:bulk_limit]
|
17
20
|
end
|
18
21
|
|
19
22
|
# Queries and returns the ElasticSearch version used.
|
data/lib/search_flip/index.rb
CHANGED
@@ -538,9 +538,13 @@ module SearchFlip
|
|
538
538
|
# raise.
|
539
539
|
|
540
540
|
def bulk(options = {})
|
541
|
-
|
541
|
+
default_options = {
|
542
|
+
http_client: connection.http_client,
|
543
|
+
bulk_limit: connection.bulk_limit,
|
544
|
+
bulk_max_mb: connection.bulk_max_mb
|
545
|
+
}
|
542
546
|
|
543
|
-
SearchFlip::Bulk.new("#{type_url}/_bulk",
|
547
|
+
SearchFlip::Bulk.new("#{type_url}/_bulk", default_options.merge(options)) do |indexer|
|
544
548
|
yield indexer
|
545
549
|
end
|
546
550
|
|
data/lib/search_flip/version.rb
CHANGED
@@ -74,5 +74,31 @@ RSpec.describe SearchFlip::Bulk do
|
|
74
74
|
|
75
75
|
expect(&block).to raise_error(SearchFlip::ResponseError)
|
76
76
|
end
|
77
|
+
|
78
|
+
it "handles overly long payloads" do
|
79
|
+
product = create(:product)
|
80
|
+
|
81
|
+
allow(product).to receive(:description).and_return("x" * 1024 * 1024 * 10)
|
82
|
+
|
83
|
+
block = lambda do
|
84
|
+
ProductIndex.bulk bulk_max_mb: 1_000 do |bulk|
|
85
|
+
100.times do
|
86
|
+
bulk.index product.id, ProductIndex.serialize(product)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
expect(&block).to raise_error(SearchFlip::ResponseError)
|
92
|
+
|
93
|
+
block = lambda do
|
94
|
+
ProductIndex.bulk bulk_max_mb: 100 do |bulk|
|
95
|
+
100.times do
|
96
|
+
bulk.index product.id, ProductIndex.serialize(product)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
expect(&block).not_to raise_error #(SearchFlip::ResponseError)
|
102
|
+
end
|
77
103
|
end
|
78
104
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: search_flip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.beta5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|