elastomer-client 3.2.3 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/devcontainer.json +46 -0
- data/.devcontainer/postCreateCommand.sh +4 -0
- data/.github/dependabot.yaml +11 -0
- data/.github/workflows/main.yml +45 -0
- data/.github/workflows/rubocop.yml +15 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +13 -65
- data/.ruby-version +1 -0
- data/CHANGELOG.md +73 -0
- data/Gemfile +18 -1
- data/README.md +110 -51
- data/Rakefile +3 -1
- data/docker/compose.yaml +71 -0
- data/docker/elasticsearch8plus.yml +13 -0
- data/docs/README.md +4 -5
- data/docs/bulk_indexing.md +1 -1
- data/docs/client.md +20 -33
- data/docs/cluster.md +8 -8
- data/docs/docs.md +5 -5
- data/docs/index.md +4 -4
- data/docs/multi_search.md +1 -1
- data/docs/notifications.md +3 -3
- data/docs/scan_scroll.md +1 -1
- data/docs/snapshots.md +1 -1
- data/docs/templates.md +1 -1
- data/elastomer-client.gemspec +7 -16
- data/lib/{elastomer → elastomer_client}/client/bulk.rb +70 -47
- data/lib/{elastomer → elastomer_client}/client/cluster.rb +18 -16
- data/lib/{elastomer → elastomer_client}/client/delete_by_query.rb +6 -4
- data/lib/{elastomer → elastomer_client}/client/docs.rb +82 -72
- data/lib/{elastomer → elastomer_client}/client/errors.rb +7 -17
- data/lib/{elastomer → elastomer_client}/client/index.rb +55 -79
- data/lib/{elastomer → elastomer_client}/client/multi_percolate.rb +7 -5
- data/lib/{elastomer → elastomer_client}/client/multi_search.rb +5 -3
- data/lib/{elastomer → elastomer_client}/client/native_delete_by_query.rb +6 -6
- data/lib/{elastomer → elastomer_client}/client/nodes.rb +11 -10
- data/lib/{elastomer → elastomer_client}/client/percolator.rb +9 -10
- data/lib/elastomer_client/client/reindex.rb +29 -0
- data/lib/{elastomer → elastomer_client}/client/repository.rb +7 -5
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec/api_spec.rb +7 -6
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec/api_spec_v5_6.rb +1 -1
- data/lib/elastomer_client/client/rest_api_spec/api_spec_v8_13.rb +7567 -0
- data/lib/elastomer_client/client/rest_api_spec/api_spec_v8_7.rb +6553 -0
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec/rest_api.rb +5 -3
- data/lib/{elastomer → elastomer_client}/client/rest_api_spec.rb +3 -2
- data/lib/{elastomer → elastomer_client}/client/scroller.rb +17 -16
- data/lib/{elastomer → elastomer_client}/client/snapshot.rb +10 -8
- data/lib/{elastomer → elastomer_client}/client/tasks.rb +9 -13
- data/lib/{elastomer → elastomer_client}/client/template.rb +10 -9
- data/lib/elastomer_client/client/update_by_query.rb +50 -0
- data/lib/{elastomer → elastomer_client}/client.rb +51 -62
- data/lib/{elastomer → elastomer_client}/core_ext/time.rb +2 -0
- data/lib/{elastomer → elastomer_client}/middleware/compress.rb +2 -2
- data/lib/{elastomer → elastomer_client}/middleware/encode_json.rb +4 -2
- data/lib/{elastomer → elastomer_client}/middleware/limit_size.rb +5 -3
- data/lib/{elastomer → elastomer_client}/middleware/opaque_id.rb +10 -7
- data/lib/{elastomer → elastomer_client}/middleware/parse_json.rb +5 -3
- data/lib/{elastomer → elastomer_client}/notifications.rb +17 -15
- data/lib/elastomer_client/version.rb +9 -0
- data/lib/elastomer_client/version_support.rb +24 -0
- data/script/bootstrap +4 -2
- data/script/console +3 -1
- data/script/generate-rest-api-spec +77 -22
- data/test/assertions.rb +32 -39
- data/test/client/bulk_test.rb +166 -141
- data/test/client/cluster_test.rb +35 -13
- data/test/client/docs_test.rb +387 -274
- data/test/client/errors_test.rb +38 -40
- data/test/client/index_test.rb +243 -202
- data/test/client/multi_percolate_test.rb +46 -41
- data/test/client/multi_search_test.rb +122 -67
- data/test/client/native_delete_by_query_test.rb +96 -88
- data/test/client/nodes_test.rb +21 -10
- data/test/client/percolator_test.rb +19 -14
- data/test/client/reindex_test.rb +76 -0
- data/test/client/repository_test.rb +31 -19
- data/test/client/rest_api_spec/api_spec_test.rb +13 -11
- data/test/client/rest_api_spec/rest_api_test.rb +9 -7
- data/test/client/scroller_test.rb +44 -70
- data/test/client/snapshot_test.rb +38 -21
- data/test/client/stubbed_client_test.rb +7 -4
- data/test/client/tasks_test.rb +12 -17
- data/test/client/template_test.rb +34 -13
- data/test/client/update_by_query_test.rb +137 -0
- data/test/client_test.rb +158 -92
- data/test/core_ext/time_test.rb +14 -12
- data/test/middleware/encode_json_test.rb +18 -7
- data/test/middleware/opaque_id_test.rb +18 -14
- data/test/middleware/parse_json_test.rb +17 -9
- data/test/mock_response.rb +30 -0
- data/test/notifications_test.rb +15 -8
- data/test/test_helper.rb +40 -97
- data/test/version_support_test.rb +13 -78
- metadata +60 -208
- data/.overcommit.yml +0 -5
- data/.travis.yml +0 -34
- data/docker/docker-compose.cibuild.yml +0 -8
- data/docker/docker-compose.es24.yml +0 -34
- data/docker/docker-compose.es56.yml +0 -37
- data/docs/warmers.md +0 -3
- data/lib/elastomer/client/app_delete_by_query.rb +0 -144
- data/lib/elastomer/client/rest_api_spec/api_spec_v2_3.rb +0 -2232
- data/lib/elastomer/client/rest_api_spec/api_spec_v2_4.rb +0 -2250
- data/lib/elastomer/client/warmer.rb +0 -98
- data/lib/elastomer/version.rb +0 -7
- data/lib/elastomer/version_support.rb +0 -182
- data/script/cibuild +0 -103
- data/script/cibuild-elastomer-client +0 -1
- data/script/cibuild-elastomer-client-es24 +0 -8
- data/script/cibuild-elastomer-client-es56 +0 -8
- data/test/client/app_delete_by_query_test.rb +0 -192
- data/test/client/es_5_x_warmer_test.rb +0 -13
- data/test/client/warmer_test.rb +0 -60
@@ -1,36 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../test_helper"
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe ElastomerClient::Client::MultiPercolate do
|
4
6
|
|
5
7
|
before do
|
8
|
+
if $client.version_support.es_version_8_plus?
|
9
|
+
skip "Multi percolate not supported in ES version #{$client.version}"
|
10
|
+
end
|
11
|
+
|
6
12
|
@name = "elastomer-mpercolate-test"
|
7
13
|
@index = $client.index(@name)
|
8
14
|
|
9
15
|
unless @index.exists?
|
10
16
|
base_mappings_settings = {
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
17
|
+
settings: { "index.number_of_shards" => 1, "index.number_of_replicas" => 0 },
|
18
|
+
mappings: {
|
19
|
+
doc1: {
|
20
|
+
_source: { enabled: true }, _all: { enabled: false },
|
21
|
+
properties: {
|
22
|
+
title: { type: "text", analyzer: "standard" },
|
23
|
+
author: { type: "keyword" }
|
18
24
|
}
|
19
25
|
},
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
26
|
+
doc2: {
|
27
|
+
_source: { enabled: true }, _all: { enabled: false },
|
28
|
+
properties: {
|
29
|
+
title: { type: "text", analyzer: "standard" },
|
30
|
+
author: { type: "keyword" }
|
25
31
|
}
|
26
32
|
}
|
27
33
|
}
|
28
34
|
}
|
29
35
|
|
30
|
-
|
31
|
-
if requires_percolator_mapping?
|
32
|
-
base_mappings_settings[:mappings][:percolator] = { :properties => { :query => { :type => "percolator" } } }
|
33
|
-
end
|
36
|
+
base_mappings_settings[:mappings][:percolator] = { properties: { query: { type: "percolator" } } }
|
34
37
|
|
35
38
|
@index.create base_mappings_settings
|
36
39
|
wait_for_index(@name)
|
@@ -58,6 +61,7 @@ describe Elastomer::Client::MultiPercolate do
|
|
58
61
|
body = body.join "\n"
|
59
62
|
h = $client.multi_percolate body
|
60
63
|
response1, response2, response3 = h["responses"]
|
64
|
+
|
61
65
|
assert_equal ["1", "2"], response1["matches"].map { |match| match["_id"] }.sort
|
62
66
|
assert_equal ["1", "3"], response2["matches"].map { |match| match["_id"] }.sort
|
63
67
|
assert_equal 2, response3["total"]
|
@@ -78,6 +82,7 @@ describe Elastomer::Client::MultiPercolate do
|
|
78
82
|
body = body.join "\n"
|
79
83
|
h = $client.mpercolate body
|
80
84
|
response1, response2, response3 = h["responses"]
|
85
|
+
|
81
86
|
assert_equal ["1", "2"], response1["matches"].map { |match| match["_id"] }.sort
|
82
87
|
assert_equal ["1", "3"], response2["matches"].map { |match| match["_id"] }.sort
|
83
88
|
assert_equal 2, response3["total"]
|
@@ -86,50 +91,50 @@ describe Elastomer::Client::MultiPercolate do
|
|
86
91
|
it "supports a nice block syntax" do
|
87
92
|
populate!
|
88
93
|
|
89
|
-
h = $client.multi_percolate(:
|
90
|
-
m.percolate :
|
91
|
-
m.percolate :
|
92
|
-
m.count({ :
|
94
|
+
h = $client.multi_percolate(index: @name, type: "doc2") do |m|
|
95
|
+
m.percolate author: "pea53"
|
96
|
+
m.percolate author: "grantr"
|
97
|
+
m.count({ author: "grantr" })
|
93
98
|
end
|
94
99
|
|
95
100
|
response1, response2, response3 = h["responses"]
|
101
|
+
|
96
102
|
assert_equal ["1", "2"], response1["matches"].map { |match| match["_id"] }.sort
|
97
103
|
assert_equal ["1", "3"], response2["matches"].map { |match| match["_id"] }.sort
|
98
104
|
assert_equal 2, response3["total"]
|
99
105
|
end
|
100
106
|
|
101
|
-
# rubocop:disable Metrics/MethodLength
|
102
107
|
def populate!
|
103
108
|
@docs.index \
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
109
|
+
_id: 1,
|
110
|
+
_type: "doc1",
|
111
|
+
title: "the author of gravatar",
|
112
|
+
author: "mojombo"
|
108
113
|
|
109
114
|
@docs.index \
|
110
|
-
:
|
111
|
-
:
|
112
|
-
:
|
113
|
-
:
|
115
|
+
_id: 2,
|
116
|
+
_type: "doc1",
|
117
|
+
title: "the author of resque",
|
118
|
+
author: "defunkt"
|
114
119
|
|
115
120
|
@docs.index \
|
116
|
-
:
|
117
|
-
:
|
118
|
-
:
|
119
|
-
:
|
121
|
+
_id: 1,
|
122
|
+
_type: "doc2",
|
123
|
+
title: "the author of logging",
|
124
|
+
author: "pea53"
|
120
125
|
|
121
126
|
@docs.index \
|
122
|
-
:
|
123
|
-
:
|
124
|
-
:
|
125
|
-
:
|
127
|
+
_id: 2,
|
128
|
+
_type: "doc2",
|
129
|
+
title: "the author of rubber-band",
|
130
|
+
author: "grantr"
|
126
131
|
|
127
132
|
percolator1 = @index.percolator "1"
|
128
|
-
percolator1.create :
|
133
|
+
percolator1.create query: { match_all: { } }
|
129
134
|
percolator2 = @index.percolator "2"
|
130
|
-
percolator2.create :
|
135
|
+
percolator2.create query: { match: { author: "pea53" } }
|
131
136
|
percolator2 = @index.percolator "3"
|
132
|
-
percolator2.create :
|
137
|
+
percolator2.create query: { match: { author: "grantr" } }
|
133
138
|
|
134
139
|
@index.refresh
|
135
140
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../test_helper"
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe ElastomerClient::Client::MultiSearch do
|
4
6
|
|
5
7
|
before do
|
6
8
|
@name = "elastomer-msearch-test"
|
@@ -8,24 +10,14 @@ describe Elastomer::Client::MultiSearch do
|
|
8
10
|
|
9
11
|
unless @index.exists?
|
10
12
|
@index.create \
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
|
15
|
-
:
|
16
|
-
|
17
|
-
:author => $client.version_support.keyword
|
18
|
-
}
|
19
|
-
},
|
20
|
-
:doc2 => {
|
21
|
-
:_source => { :enabled => true }, :_all => { :enabled => false },
|
22
|
-
:properties => {
|
23
|
-
:title => $client.version_support.text(analyzer: "standard"),
|
24
|
-
:author => $client.version_support.keyword
|
25
|
-
}
|
13
|
+
settings: { "index.number_of_shards" => 1, "index.number_of_replicas" => 0 },
|
14
|
+
mappings: mappings_wrapper("book", {
|
15
|
+
_source: { enabled: true },
|
16
|
+
properties: {
|
17
|
+
title: { type: "text", analyzer: "standard" },
|
18
|
+
author: { type: "keyword" }
|
26
19
|
}
|
27
|
-
}
|
28
|
-
|
20
|
+
}, !$client.version_support.es_version_8_plus?)
|
29
21
|
wait_for_index(@name)
|
30
22
|
end
|
31
23
|
|
@@ -40,28 +32,41 @@ describe Elastomer::Client::MultiSearch do
|
|
40
32
|
populate!
|
41
33
|
|
42
34
|
body = [
|
43
|
-
'{"index" : "elastomer-msearch-test"
|
35
|
+
'{"index" : "elastomer-msearch-test"}',
|
44
36
|
'{"query" : {"match_all" : {}}}',
|
45
|
-
'{"index" : "elastomer-msearch-test"
|
46
|
-
'{"query" : {"match": {"author" : "
|
37
|
+
'{"index" : "elastomer-msearch-test"}',
|
38
|
+
'{"query" : {"match": {"author" : "Author 2"}}}',
|
47
39
|
nil
|
48
40
|
]
|
49
41
|
body = body.join "\n"
|
50
42
|
h = $client.multi_search body
|
51
43
|
response1, response2 = h["responses"]
|
52
|
-
|
53
|
-
|
44
|
+
|
45
|
+
if $client.version_support.es_version_8_plus?
|
46
|
+
assert_equal 2, response1["hits"]["total"]["value"]
|
47
|
+
assert_equal 1, response2["hits"]["total"]["value"]
|
48
|
+
else
|
49
|
+
assert_equal 2, response1["hits"]["total"]
|
50
|
+
assert_equal 1, response2["hits"]["total"]
|
51
|
+
end
|
52
|
+
|
54
53
|
assert_equal "2", response2["hits"]["hits"][0]["_id"]
|
55
54
|
|
56
55
|
body = [
|
57
56
|
"{}",
|
58
|
-
'{"query" : {"match": {"author" : "
|
57
|
+
'{"query" : {"match": {"author" : "Author 2"}}}',
|
59
58
|
nil
|
60
59
|
]
|
61
60
|
body = body.join "\n"
|
62
|
-
h = $client.multi_search body, :
|
61
|
+
h = $client.multi_search body, index: @name
|
63
62
|
response1 = h["responses"].first
|
64
|
-
|
63
|
+
|
64
|
+
if $client.version_support.es_version_8_plus?
|
65
|
+
assert_equal 1, response1["hits"]["total"]["value"]
|
66
|
+
else
|
67
|
+
assert_equal 1, response1["hits"]["total"]
|
68
|
+
end
|
69
|
+
|
65
70
|
assert_equal "2", response1["hits"]["hits"][0]["_id"]
|
66
71
|
end
|
67
72
|
|
@@ -69,28 +74,41 @@ describe Elastomer::Client::MultiSearch do
|
|
69
74
|
populate!
|
70
75
|
|
71
76
|
body = [
|
72
|
-
'{"index" : "elastomer-msearch-test"
|
77
|
+
'{"index" : "elastomer-msearch-test"}',
|
73
78
|
'{"query" : {"match_all" : {}}}',
|
74
|
-
'{"index" : "elastomer-msearch-test"
|
75
|
-
'{"query" : {"match": {"author" : "
|
79
|
+
'{"index" : "elastomer-msearch-test"}',
|
80
|
+
'{"query" : {"match": {"author" : "Author 2"}}}',
|
76
81
|
nil
|
77
82
|
]
|
78
83
|
body = body.join "\n"
|
79
84
|
h = $client.msearch body
|
80
85
|
response1, response2 = h["responses"]
|
81
|
-
|
82
|
-
|
86
|
+
|
87
|
+
if $client.version_support.es_version_8_plus?
|
88
|
+
assert_equal 2, response1["hits"]["total"]["value"]
|
89
|
+
assert_equal 1, response2["hits"]["total"]["value"]
|
90
|
+
else
|
91
|
+
assert_equal 2, response1["hits"]["total"]
|
92
|
+
assert_equal 1, response2["hits"]["total"]
|
93
|
+
end
|
94
|
+
|
83
95
|
assert_equal "2", response2["hits"]["hits"][0]["_id"]
|
84
96
|
|
85
97
|
body = [
|
86
98
|
"{}",
|
87
|
-
'{"query" : {"match": {"author" : "
|
99
|
+
'{"query" : {"match": {"author" : "Author 2"}}}',
|
88
100
|
nil
|
89
101
|
]
|
90
102
|
body = body.join "\n"
|
91
|
-
h = $client.msearch body, :
|
103
|
+
h = $client.msearch body, index: @name
|
92
104
|
response1 = h["responses"].first
|
93
|
-
|
105
|
+
|
106
|
+
if $client.version_support.es_version_8_plus?
|
107
|
+
assert_equal 1, response1["hits"]["total"]["value"]
|
108
|
+
else
|
109
|
+
assert_equal 1, response1["hits"]["total"]
|
110
|
+
end
|
111
|
+
|
94
112
|
assert_equal "2", response1["hits"]["hits"][0]["_id"]
|
95
113
|
end
|
96
114
|
|
@@ -98,61 +116,98 @@ describe Elastomer::Client::MultiSearch do
|
|
98
116
|
populate!
|
99
117
|
|
100
118
|
h = $client.multi_search do |m|
|
101
|
-
m.search({:
|
102
|
-
m.search({:
|
119
|
+
m.search({query: { match_all: {}}}, index: @name)
|
120
|
+
m.search({query: { match: { "title" => "author" }}}, index: @name)
|
103
121
|
end
|
104
122
|
|
105
123
|
response1, response2 = h["responses"]
|
106
124
|
|
107
|
-
|
108
|
-
|
125
|
+
if $client.version_support.es_version_8_plus?
|
126
|
+
assert_equal 2, response1["hits"]["total"]["value"]
|
127
|
+
assert_equal 2, response2["hits"]["total"]["value"]
|
128
|
+
else
|
129
|
+
assert_equal 2, response1["hits"]["total"]
|
130
|
+
assert_equal 2, response2["hits"]["total"]
|
131
|
+
end
|
109
132
|
|
110
133
|
h = @index.multi_search do |m|
|
111
|
-
m.search({:
|
112
|
-
m.search({:
|
134
|
+
m.search({query: { match_all: {}}})
|
135
|
+
m.search({query: { match: { "title" => "author" }}})
|
113
136
|
end
|
114
137
|
|
115
138
|
response1, response2 = h["responses"]
|
116
139
|
|
117
|
-
|
118
|
-
|
140
|
+
if $client.version_support.es_version_8_plus?
|
141
|
+
assert_equal 2, response1["hits"]["total"]["value"]
|
142
|
+
assert_equal 2, response2["hits"]["total"]["value"]
|
143
|
+
else
|
144
|
+
assert_equal 2, response1["hits"]["total"]
|
145
|
+
assert_equal 2, response2["hits"]["total"]
|
146
|
+
end
|
119
147
|
|
120
|
-
|
121
|
-
|
122
|
-
m.search({:
|
148
|
+
type = $client.version_support.es_version_8_plus? ? "" : "book"
|
149
|
+
h = @index.docs(type).multi_search do |m|
|
150
|
+
m.search({query: { match_all: {}}})
|
151
|
+
m.search({query: { match: { "title" => "2" }}})
|
123
152
|
end
|
124
153
|
|
125
154
|
response1, response2 = h["responses"]
|
126
155
|
|
127
|
-
|
128
|
-
|
156
|
+
if $client.version_support.es_version_8_plus?
|
157
|
+
assert_equal 2, response1["hits"]["total"]["value"]
|
158
|
+
assert_equal 1, response2["hits"]["total"]["value"]
|
159
|
+
else
|
160
|
+
assert_equal 2, response1["hits"]["total"]
|
161
|
+
assert_equal 1, response2["hits"]["total"]
|
162
|
+
end
|
129
163
|
end
|
130
164
|
|
131
|
-
|
132
|
-
|
133
|
-
@docs.index \
|
134
|
-
:_id => 1,
|
135
|
-
:_type => "doc1",
|
136
|
-
:title => "the author of gravatar",
|
137
|
-
:author => "mojombo"
|
165
|
+
it "performs suggestion queries using the search endpoint" do
|
166
|
+
populate!
|
138
167
|
|
139
|
-
@
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
168
|
+
h = @index.multi_search do |m|
|
169
|
+
m.search({
|
170
|
+
query: {
|
171
|
+
match: {
|
172
|
+
title: "by author"
|
173
|
+
}
|
174
|
+
},
|
175
|
+
suggest: {
|
176
|
+
suggestion1: {
|
177
|
+
text: "by author",
|
178
|
+
term: {
|
179
|
+
field: "author"
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
|
+
})
|
184
|
+
end
|
144
185
|
|
186
|
+
response = h["responses"][0]
|
187
|
+
|
188
|
+
if $client.version_support.es_version_8_plus?
|
189
|
+
assert_equal 2, response["hits"]["total"]["value"]
|
190
|
+
else
|
191
|
+
assert_equal 2, response["hits"]["total"]
|
192
|
+
end
|
193
|
+
|
194
|
+
refute_nil response["suggest"], "expected suggester text to be returned"
|
195
|
+
end
|
196
|
+
|
197
|
+
def populate!
|
145
198
|
@docs.index \
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
199
|
+
document_wrapper("book", {
|
200
|
+
_id: 1,
|
201
|
+
title: "Book 1 by author 1",
|
202
|
+
author: "Author 1"
|
203
|
+
})
|
150
204
|
|
151
205
|
@docs.index \
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
206
|
+
document_wrapper("book", {
|
207
|
+
_id: 2,
|
208
|
+
title: "Book 2 by author 2",
|
209
|
+
author: "Author 2"
|
210
|
+
})
|
156
211
|
|
157
212
|
@index.refresh
|
158
213
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "../test_helper"
|
2
4
|
|
3
|
-
describe
|
5
|
+
describe ElastomerClient::Client::NativeDeleteByQuery do
|
4
6
|
before do
|
5
7
|
@index = $client.index "elastomer-delete-by-query-test"
|
6
8
|
@index.delete if @index.exists?
|
@@ -11,113 +13,119 @@ describe Elastomer::Client::NativeDeleteByQuery do
|
|
11
13
|
@index.delete if @index.exists?
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
describe "when an index with documents exists" do
|
17
|
+
before do
|
18
|
+
@index.create(nil)
|
19
|
+
wait_for_index(@index.name)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
it "deletes by query" do
|
23
|
+
@docs.index({ _id: 0, name: "mittens" })
|
24
|
+
@docs.index({ _id: 1, name: "luna" })
|
24
25
|
|
25
|
-
|
26
|
+
@index.refresh
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
28
|
+
query = {
|
29
|
+
query: {
|
30
|
+
match: {
|
31
|
+
name: "mittens"
|
32
32
|
}
|
33
33
|
}
|
34
|
+
}
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@index.refresh
|
44
|
-
response = @docs.multi_get(:ids => [0, 1])
|
45
|
-
refute_found response.fetch("docs")[0]
|
46
|
-
assert_found response.fetch("docs")[1]
|
47
|
-
end
|
36
|
+
response = @index.native_delete_by_query(query)
|
37
|
+
|
38
|
+
refute_nil response["took"]
|
39
|
+
refute(response["timed_out"])
|
40
|
+
assert_equal(1, response["batches"])
|
41
|
+
assert_equal(1, response["total"])
|
42
|
+
assert_equal(1, response["deleted"])
|
43
|
+
assert_empty(response["failures"])
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
45
|
+
@index.refresh
|
46
|
+
response = @docs.multi_get(ids: [0, 1])
|
47
|
+
|
48
|
+
refute_found response.fetch("docs")[0]
|
49
|
+
assert_found response.fetch("docs")[1]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "fails when internal version is 0" do
|
53
|
+
if $client.version_support.es_version_8_plus?
|
54
|
+
skip "Concurrency control with internal version is not supported in ES #{$client.version}"
|
55
|
+
end
|
56
|
+
@docs.index({_id: 0, name: "mittens"})
|
57
|
+
# Creating a document with external version 0 also sets the internal version to 0
|
58
|
+
# Otherwise you can't index a document with version 0.
|
59
|
+
@docs.index({_id: 1, _version: 0, _version_type: "external", name: "mittens"})
|
60
|
+
@index.refresh
|
61
|
+
|
62
|
+
query = {
|
63
|
+
query: {
|
64
|
+
match: {
|
65
|
+
name: "mittens"
|
61
66
|
}
|
62
67
|
}
|
68
|
+
}
|
63
69
|
|
64
|
-
|
65
|
-
|
66
|
-
end
|
70
|
+
assert_raises(ElastomerClient::Client::RequestError) do
|
71
|
+
@index.native_delete_by_query(query)
|
67
72
|
end
|
73
|
+
end
|
68
74
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
75
|
+
it "fails when an unknown parameter is provided" do
|
76
|
+
assert_raises(ElastomerClient::Client::IllegalArgument) do
|
77
|
+
@index.native_delete_by_query({}, foo: "bar")
|
73
78
|
end
|
79
|
+
end
|
74
80
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
81
|
+
it "deletes by query when routing is specified" do
|
82
|
+
index = $client.index "elastomer-delete-by-query-routing-test"
|
83
|
+
index.delete if index.exists?
|
84
|
+
type = "docs"
|
85
|
+
# default number of shards in ES8 is 1, so set it to 2 shards so routing to different shards can be tested
|
86
|
+
settings = $client.version_support.es_version_8_plus? ? { number_of_shards: 2 } : {}
|
87
|
+
index.create({
|
88
|
+
settings:,
|
89
|
+
mappings: mappings_wrapper(type, {
|
90
|
+
properties: {
|
91
|
+
name: { type: "text", analyzer: "standard" },
|
92
|
+
},
|
93
|
+
_routing: { required: true }
|
94
|
+
})
|
95
|
+
})
|
96
|
+
wait_for_index(@index.name)
|
97
|
+
docs = index.docs(type)
|
98
|
+
|
99
|
+
docs.index({ _id: 0, _routing: "cat", name: "mittens" })
|
100
|
+
docs.index({ _id: 1, _routing: "cat", name: "luna" })
|
101
|
+
docs.index({ _id: 2, _routing: "dog", name: "mittens" })
|
102
|
+
|
103
|
+
query = {
|
104
|
+
query: {
|
105
|
+
match: {
|
106
|
+
name: "mittens"
|
92
107
|
}
|
93
108
|
}
|
109
|
+
}
|
94
110
|
|
95
|
-
|
96
|
-
|
111
|
+
index.refresh
|
112
|
+
response = index.native_delete_by_query(query, routing: "cat")
|
97
113
|
|
98
|
-
|
114
|
+
assert_equal(1, response["deleted"])
|
99
115
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
refute_found response["docs"][0]
|
108
|
-
assert_found response["docs"][1]
|
109
|
-
assert_found response["docs"][2]
|
116
|
+
response = docs.multi_get({
|
117
|
+
docs: [
|
118
|
+
{ _id: 0, routing: "cat" },
|
119
|
+
{ _id: 1, routing: "cat" },
|
120
|
+
{ _id: 2, routing: "dog" },
|
121
|
+
]
|
122
|
+
})
|
110
123
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
it "raises an error" do
|
117
|
-
assert_raises(Elastomer::Client::IncompatibleVersionException) do
|
118
|
-
@index.native_delete_by_query({query: {match_all: {}}})
|
119
|
-
end
|
120
|
-
end
|
124
|
+
refute_found response["docs"][0]
|
125
|
+
assert_found response["docs"][1]
|
126
|
+
assert_found response["docs"][2]
|
127
|
+
|
128
|
+
index.delete if index.exists?
|
121
129
|
end
|
122
130
|
end
|
123
131
|
end
|