search_flip 2.0.0.beta5 → 2.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/search_flip/aggregation.rb +2 -1
- data/lib/search_flip/bulk.rb +17 -1
- data/lib/search_flip/criteria.rb +69 -7
- data/lib/search_flip/index.rb +1 -1
- data/lib/search_flip/version.rb +1 -1
- data/spec/search_flip/aggregation_spec.rb +2 -1
- data/spec/search_flip/bulk_spec.rb +1 -1
- data/spec/search_flip/criteria_spec.rb +29 -1
- data/spec/search_flip/index_spec.rb +34 -1
- 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: 47ca9a2ae9454e232a82a2d0ca91d58cb0f8d79e087795c0e9dbae5ad9ac6216
|
4
|
+
data.tar.gz: 721e6a0b0cc6abbf8d501e09903a1c9a3cb0ba526f1c9a403461ec38c3607f15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0b4d33d00bb54b2d0b16fd1df450f93a412097312ac8726ab5f3d76bfd5c4c89a1374d6f61cf62920ebd4d86f209da330b20dd61a446c0d3bf5b25036b4cee3
|
7
|
+
data.tar.gz: 4d18ae080aa3dbdbdd024e5a3ce33529c002162bf9b5057848c7813546aab64dc82d2cd0ff91de26b155898559834bb8aabec961bea51488abe829ca5782dc52
|
data/README.md
CHANGED
@@ -91,6 +91,7 @@ Available config options are:
|
|
91
91
|
can be useful to separate the indices of e.g. testing and development environments.
|
92
92
|
* `base_url` to tell search_flip how to connect to your cluster
|
93
93
|
* `bulk_limit` a global limit for bulk requests
|
94
|
+
* `bulk_max_mb` a global limit for the payload of bulk requests
|
94
95
|
* `auto_refresh` tells search_flip to automatically refresh an index after
|
95
96
|
import, index, delete, etc operations. This is e.g. usuful for testing, etc.
|
96
97
|
Defaults to false.
|
@@ -65,7 +65,8 @@ module SearchFlip
|
|
65
65
|
:profile_value, :failsafe_value, :terminate_after_value, :timeout_value, :offset_value, :limit_value,
|
66
66
|
:scroll_args, :highlight_values, :suggest_values, :custom_value, :source_value, :sort_values,
|
67
67
|
:includes_values, :preload_values, :eager_load_values, :post_search_values, :post_must_values,
|
68
|
-
:post_must_not_values, :post_should_values, :post_filter_values
|
68
|
+
:post_must_not_values, :post_should_values, :post_filter_values, :preference_value,
|
69
|
+
:search_type_value, :routing_value
|
69
70
|
]
|
70
71
|
|
71
72
|
unsupported_methods.each do |unsupported_method|
|
data/lib/search_flip/bulk.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
|
2
2
|
module SearchFlip
|
3
|
+
# @api private
|
4
|
+
#
|
3
5
|
# The SearchFlip::Bulk class implements the bulk support, ie it collects
|
4
6
|
# single requests and emits batches of requests.
|
5
7
|
#
|
@@ -16,6 +18,8 @@ module SearchFlip
|
|
16
18
|
|
17
19
|
attr_reader :url, :options, :ignore_errors
|
18
20
|
|
21
|
+
# @api private
|
22
|
+
#
|
19
23
|
# Builds and yields a new Bulk object, ie initiates the buffer, yields,
|
20
24
|
# sends batches of records each time the buffer is full, and sends a final
|
21
25
|
# batch after the yielded code returns and there are still documents
|
@@ -33,8 +37,10 @@ module SearchFlip
|
|
33
37
|
#
|
34
38
|
# @param url [String] The endpoint to send bulk requests to
|
35
39
|
# @param options [Hash] Options for the bulk requests
|
36
|
-
# @option options
|
40
|
+
# @option options bulk_limit [Fixnum] The maximum number of documents per bulk
|
37
41
|
# request
|
42
|
+
# @option bulk_max_mb [Fixnum] The maximum payload size in megabytes per
|
43
|
+
# bulk request
|
38
44
|
# @option options ignore_errors [Array, Fixnum] Errors that should be
|
39
45
|
# ignored. If you eg want to ignore errors resulting from conflicts,
|
40
46
|
# you can specify to ignore 409 here.
|
@@ -62,6 +68,8 @@ module SearchFlip
|
|
62
68
|
upload if @num > 0
|
63
69
|
end
|
64
70
|
|
71
|
+
# @api private
|
72
|
+
#
|
65
73
|
# Adds an index request to the bulk batch.
|
66
74
|
#
|
67
75
|
# @param id [Fixnum, String] The document/record id
|
@@ -73,6 +81,8 @@ module SearchFlip
|
|
73
81
|
perform :index, id, SearchFlip::JSON.generate(object), options
|
74
82
|
end
|
75
83
|
|
84
|
+
# @api private
|
85
|
+
#
|
76
86
|
# Adds an index request to the bulk batch
|
77
87
|
#
|
78
88
|
# @see #index
|
@@ -81,6 +91,8 @@ module SearchFlip
|
|
81
91
|
index(*args)
|
82
92
|
end
|
83
93
|
|
94
|
+
# @api private
|
95
|
+
#
|
84
96
|
# Adds a create request to the bulk batch.
|
85
97
|
#
|
86
98
|
# @param id [Fixnum, String] The document/record id
|
@@ -92,6 +104,8 @@ module SearchFlip
|
|
92
104
|
perform :create, id, SearchFlip::JSON.generate(object), options
|
93
105
|
end
|
94
106
|
|
107
|
+
# @api private
|
108
|
+
#
|
95
109
|
# Adds a update request to the bulk batch.
|
96
110
|
#
|
97
111
|
# @param id [Fixnum, String] The document/record id
|
@@ -103,6 +117,8 @@ module SearchFlip
|
|
103
117
|
perform :update, id, SearchFlip::JSON.generate(object), options
|
104
118
|
end
|
105
119
|
|
120
|
+
# @api private
|
121
|
+
#
|
106
122
|
# Adds a delete request to the bulk batch.
|
107
123
|
#
|
108
124
|
# @param id [Fixnum, String] The document/record id
|
data/lib/search_flip/criteria.rb
CHANGED
@@ -19,8 +19,10 @@ module SearchFlip
|
|
19
19
|
include SearchFlip::Aggregatable
|
20
20
|
extend Forwardable
|
21
21
|
|
22
|
-
attr_accessor :target, :profile_value, :source_value, :sort_values, :highlight_values, :suggest_values,
|
23
|
-
:
|
22
|
+
attr_accessor :target, :profile_value, :source_value, :sort_values, :highlight_values, :suggest_values,
|
23
|
+
:offset_value, :limit_value, :includes_values, :eager_load_values, :preload_values, :failsafe_value,
|
24
|
+
:scroll_args, :custom_value, :terminate_after_value, :timeout_value, :preference_value,
|
25
|
+
:search_type_value, :routing_value
|
24
26
|
|
25
27
|
# Creates a new criteria while merging the attributes (constraints,
|
26
28
|
# settings, etc) of the current criteria with the attributes of another one
|
@@ -46,6 +48,9 @@ module SearchFlip
|
|
46
48
|
criteria.limit_value = other.limit_value if other.limit_value
|
47
49
|
criteria.scroll_args = other.scroll_args if other.scroll_args
|
48
50
|
criteria.source_value = other.source_value if other.source_value
|
51
|
+
criteria.preference_value = other.preference_value if other.preference_value
|
52
|
+
criteria.search_type_value = other.search_type_value if other.search_type_value
|
53
|
+
criteria.routing_value = other.routing_value if other.routing_value
|
49
54
|
|
50
55
|
criteria.sort_values = (criteria.sort_values || []) + other.sort_values if other.sort_values
|
51
56
|
criteria.includes_values = (criteria.includes_values || []) + other.includes_values if other.includes_values
|
@@ -69,6 +74,54 @@ module SearchFlip
|
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
77
|
+
# Specifies a preference value for the request. Check out the elasticsearch
|
78
|
+
# docs for further details.
|
79
|
+
#
|
80
|
+
# @example
|
81
|
+
# CommentIndex.preference("_primary")
|
82
|
+
#
|
83
|
+
# @param value The preference value
|
84
|
+
#
|
85
|
+
# @return [SearchFlip::Criteria] A newly created extended criteria
|
86
|
+
|
87
|
+
def preference(value)
|
88
|
+
fresh.tap do |criteria|
|
89
|
+
criteria.preference_value = value
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Specifies the search type value for the request. Check out the elasticsearch
|
94
|
+
# docs for further details.
|
95
|
+
#
|
96
|
+
# @example
|
97
|
+
# CommentIndex.search_type("dfs_query_then_fetch")
|
98
|
+
#
|
99
|
+
# @param value The search type value
|
100
|
+
#
|
101
|
+
# @return [SearchFlip::Criteria] A newly created extended criteria
|
102
|
+
|
103
|
+
def search_type(value)
|
104
|
+
fresh.tap do |criteria|
|
105
|
+
criteria.search_type_value = value
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Specifies the routing value for the request. Check out the elasticsearch
|
110
|
+
# docs for further details.
|
111
|
+
#
|
112
|
+
# @example
|
113
|
+
# CommentIndex.routing("user_id")
|
114
|
+
#
|
115
|
+
# @param value The search type value
|
116
|
+
#
|
117
|
+
# @return [SearchFlip::Criteria] A newly created extended criteria
|
118
|
+
|
119
|
+
def routing(value)
|
120
|
+
fresh.tap do |criteria|
|
121
|
+
criteria.routing_value = value
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
72
125
|
# Specifies a query timeout, such that the processing will be stopped after
|
73
126
|
# that timeout and only the results calculated up to that point will be
|
74
127
|
# processed and returned.
|
@@ -360,9 +413,9 @@ module SearchFlip
|
|
360
413
|
dupped_request.delete(:size)
|
361
414
|
|
362
415
|
if connection.version.to_i >= 5
|
363
|
-
connection.http_client.post("#{target.type_url}/_delete_by_query", json: dupped_request)
|
416
|
+
connection.http_client.post("#{target.type_url}/_delete_by_query", params: request_params, json: dupped_request)
|
364
417
|
else
|
365
|
-
connection.http_client.delete("#{target.type_url}/_query", json: dupped_request)
|
418
|
+
connection.http_client.delete("#{target.type_url}/_query", params: request_params, json: dupped_request)
|
366
419
|
end
|
367
420
|
|
368
421
|
target.refresh if SearchFlip::Config[:auto_refresh]
|
@@ -722,21 +775,22 @@ module SearchFlip
|
|
722
775
|
if connection.version.to_i >= 2
|
723
776
|
http_request.post(
|
724
777
|
"#{connection.base_url}/_search/scroll",
|
778
|
+
params: request_params,
|
725
779
|
json: { scroll: scroll_args[:timeout], scroll_id: scroll_args[:id] }
|
726
780
|
)
|
727
781
|
else
|
728
782
|
http_request
|
729
783
|
.headers(content_type: "text/plain")
|
730
|
-
.post("#{connection.base_url}/_search/scroll", params:
|
784
|
+
.post("#{connection.base_url}/_search/scroll", params: request_params.merge(scroll: scroll_args[:timeout]), body: scroll_args[:id])
|
731
785
|
end
|
732
786
|
elsif scroll_args
|
733
787
|
http_request.post(
|
734
788
|
"#{target.type_url}/_search",
|
735
|
-
params:
|
789
|
+
params: request_params.merge(scroll: scroll_args[:timeout]),
|
736
790
|
json: request
|
737
791
|
)
|
738
792
|
else
|
739
|
-
http_request.post("#{target.type_url}/_search", json: request)
|
793
|
+
http_request.post("#{target.type_url}/_search", params: request_params, json: request)
|
740
794
|
end
|
741
795
|
|
742
796
|
SearchFlip::Response.new(self, http_response.parse)
|
@@ -824,5 +878,13 @@ module SearchFlip
|
|
824
878
|
criteria = criteria.scroll(id: criteria.scroll_id, timeout: timeout)
|
825
879
|
end
|
826
880
|
end
|
881
|
+
|
882
|
+
def request_params
|
883
|
+
res = {}
|
884
|
+
res[:preference] = preference_value if preference_value
|
885
|
+
res[:search_type] = search_type_value if search_type_value
|
886
|
+
res[:routing] = routing_value if routing_value
|
887
|
+
res
|
888
|
+
end
|
827
889
|
end
|
828
890
|
end
|
data/lib/search_flip/index.rb
CHANGED
@@ -252,7 +252,7 @@ module SearchFlip
|
|
252
252
|
:includes, :eager_load, :preload, :sort, :resort, :order, :reorder, :offset, :limit, :paginate,
|
253
253
|
:page, :per, :search, :highlight, :suggest, :custom, :find_in_batches, :find_results_in_batches,
|
254
254
|
:find_each, :find_each_result, :failsafe, :total_entries, :total_count, :timeout, :terminate_after,
|
255
|
-
:records, :results, :should, :should_not, :must, :must_not
|
255
|
+
:records, :results, :should, :should_not, :must, :must_not, :preference, :search_type, :routing
|
256
256
|
|
257
257
|
# Override to specify the type name used within ElasticSearch. Recap,
|
258
258
|
# this gem uses an individual index for each index class, because
|
data/lib/search_flip/version.rb
CHANGED
@@ -288,7 +288,8 @@ RSpec.describe SearchFlip::Aggregation do
|
|
288
288
|
:profile_value, :failsafe_value, :terminate_after_value, :timeout_value, :offset_value, :limit_value,
|
289
289
|
:scroll_args, :highlight_values, :suggest_values, :custom_value, :source_value, :sort_values,
|
290
290
|
:includes_values, :preload_values, :eager_load_values, :post_search_values, :post_must_values,
|
291
|
-
:post_must_not_values, :post_should_values, :post_filter_values
|
291
|
+
:post_must_not_values, :post_should_values, :post_filter_values, :preference_value,
|
292
|
+
:search_type_value, :routing_value
|
292
293
|
]
|
293
294
|
|
294
295
|
unsupported_methods.each do |unsupported_method|
|
@@ -35,7 +35,8 @@ RSpec.describe SearchFlip::Criteria do
|
|
35
35
|
describe "assignments" do
|
36
36
|
methods = [
|
37
37
|
:profile_value, :failsafe_value, :terminate_after_value, :timeout_value,
|
38
|
-
:offset_value, :limit_value, :scroll_args, :source_value
|
38
|
+
:offset_value, :limit_value, :scroll_args, :source_value, :preference_value,
|
39
|
+
:search_type_value, :routing_value
|
39
40
|
]
|
40
41
|
|
41
42
|
methods.each do |method|
|
@@ -1023,5 +1024,32 @@ RSpec.describe SearchFlip::Criteria do
|
|
1023
1024
|
expect(request[:custom_key]).to eq("custom_value")
|
1024
1025
|
end
|
1025
1026
|
end
|
1027
|
+
|
1028
|
+
describe "#preference" do
|
1029
|
+
it "sets the preference" do
|
1030
|
+
stub_request(:post, "http://127.0.0.1:9200/products/products/_search?preference=value")
|
1031
|
+
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
|
1032
|
+
|
1033
|
+
ProductIndex.preference("value").execute
|
1034
|
+
end
|
1035
|
+
end
|
1036
|
+
|
1037
|
+
describe "#search_type" do
|
1038
|
+
it "sets the search_type" do
|
1039
|
+
stub_request(:post, "http://127.0.0.1:9200/products/products/_search?search_type=value")
|
1040
|
+
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
|
1041
|
+
|
1042
|
+
ProductIndex.search_type("value").execute
|
1043
|
+
end
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
describe "#routing" do
|
1047
|
+
it "sets the search_type" do
|
1048
|
+
stub_request(:post, "http://127.0.0.1:9200/products/products/_search?routing=value")
|
1049
|
+
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
|
1050
|
+
|
1051
|
+
ProductIndex.routing("value").execute
|
1052
|
+
end
|
1053
|
+
end
|
1026
1054
|
end
|
1027
1055
|
|
@@ -14,7 +14,7 @@ RSpec.describe SearchFlip::Index do
|
|
14
14
|
:find_in_batches, :highlight, :suggest, :custom, :find_each, :failsafe,
|
15
15
|
:total_entries, :total_count, :terminate_after, :timeout, :records, :results,
|
16
16
|
:should, :should_not, :must, :must_not, :find_each_result,
|
17
|
-
:find_results_in_batches
|
17
|
+
:find_results_in_batches, :preference, :search_type, :routing
|
18
18
|
]
|
19
19
|
|
20
20
|
methods.each do |method|
|
@@ -448,6 +448,39 @@ RSpec.describe SearchFlip::Index do
|
|
448
448
|
|
449
449
|
expect(&bulk).not_to(change { ProductIndex.total_count })
|
450
450
|
end
|
451
|
+
|
452
|
+
it "passes default options" do
|
453
|
+
allow(SearchFlip::Bulk).to receive(:new)
|
454
|
+
|
455
|
+
ProductIndex.bulk do |indexer|
|
456
|
+
indexer.index 1, id: 1
|
457
|
+
end
|
458
|
+
|
459
|
+
connection = ProductIndex.connection
|
460
|
+
|
461
|
+
expect(SearchFlip::Bulk).to have_received(:new).with(
|
462
|
+
anything,
|
463
|
+
http_client: connection.http_client,
|
464
|
+
bulk_limit: connection.bulk_limit,
|
465
|
+
bulk_max_mb: connection.bulk_max_mb
|
466
|
+
)
|
467
|
+
end
|
468
|
+
|
469
|
+
it "passes custom options" do
|
470
|
+
allow(SearchFlip::Bulk).to receive(:new)
|
471
|
+
|
472
|
+
options = {
|
473
|
+
bulk_limit: "bulk limit",
|
474
|
+
bulk_max_mb: "bulk max mb",
|
475
|
+
http_client: "http client"
|
476
|
+
}
|
477
|
+
|
478
|
+
ProductIndex.bulk(options) do |indexer|
|
479
|
+
indexer.index 1, id: 1
|
480
|
+
end
|
481
|
+
|
482
|
+
expect(SearchFlip::Bulk).to have_received(:new).with(anything, options)
|
483
|
+
end
|
451
484
|
end
|
452
485
|
|
453
486
|
describe ".connection" do
|
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.beta6
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|