Commit 84eea3b10ef40f135eb463bc1317a3bff3a5ed8a
1 parent
2e6c82a1
Exists in
master
and in
21 other branches
Added support for Elasticsearch 5.0 beta
Showing
6 changed files
with
49 additions
and
4 deletions
Show diff stats
.travis.yml
@@ -34,7 +34,7 @@ matrix: | @@ -34,7 +34,7 @@ matrix: | ||
34 | - gemfile: Gemfile | 34 | - gemfile: Gemfile |
35 | env: ELASTICSEARCH_VERSION=2.0.0 | 35 | env: ELASTICSEARCH_VERSION=2.0.0 |
36 | - gemfile: Gemfile | 36 | - gemfile: Gemfile |
37 | - env: ELASTICSEARCH_VERSION=5.0.0-alpha5 | 37 | + env: ELASTICSEARCH_VERSION=5.0.0-beta1 |
38 | # - gemfile: test/gemfiles/nobrainer.gemfile | 38 | # - gemfile: test/gemfiles/nobrainer.gemfile |
39 | # env: NOBRAINER=true | 39 | # env: NOBRAINER=true |
40 | allow_failures: | 40 | allow_failures: |
CHANGELOG.md
lib/searchkick/query.rb
@@ -384,13 +384,22 @@ module Searchkick | @@ -384,13 +384,22 @@ module Searchkick | ||
384 | payload[:fields] = options[:select] if options[:select] != true | 384 | payload[:fields] = options[:select] if options[:select] != true |
385 | elsif options[:select_v2] | 385 | elsif options[:select_v2] |
386 | if options[:select_v2] == [] | 386 | if options[:select_v2] == [] |
387 | - payload[:fields] = [] # intuitively [] makes sense to return no fields, but ES by default returns all fields | 387 | + # intuitively [] makes sense to return no fields, but ES by default returns all fields |
388 | + if below50? | ||
389 | + payload[:fields] = [] | ||
390 | + else | ||
391 | + payload[:_source] = false | ||
392 | + end | ||
388 | else | 393 | else |
389 | payload[:_source] = options[:select_v2] | 394 | payload[:_source] = options[:select_v2] |
390 | end | 395 | end |
391 | elsif load | 396 | elsif load |
392 | # don't need any fields since we're going to load them from the DB anyways | 397 | # don't need any fields since we're going to load them from the DB anyways |
393 | - payload[:fields] = [] | 398 | + if below50? |
399 | + payload[:fields] = [] | ||
400 | + else | ||
401 | + payload[:_source] = false | ||
402 | + end | ||
394 | end | 403 | end |
395 | 404 | ||
396 | if options[:type] || (klass != searchkick_klass && searchkick_index) | 405 | if options[:type] || (klass != searchkick_klass && searchkick_index) |
test/index_test.rb
@@ -112,6 +112,9 @@ class IndexTest < Minitest::Test | @@ -112,6 +112,9 @@ class IndexTest < Minitest::Test | ||
112 | end | 112 | end |
113 | 113 | ||
114 | def test_analyzed_only | 114 | def test_analyzed_only |
115 | + # skip for 5.0 since it throws | ||
116 | + # Cannot search on field [alt_description] since it is not indexed. | ||
117 | + skip unless elasticsearch_below50? | ||
115 | store [{name: "Product A", alt_description: "Hello"}] | 118 | store [{name: "Product A", alt_description: "Hello"}] |
116 | assert_search "*", [], where: {alt_description: "Hello"} | 119 | assert_search "*", [], where: {alt_description: "Hello"} |
117 | end | 120 | end |
test/query_test.rb
@@ -12,8 +12,9 @@ class QueryTest < Minitest::Test | @@ -12,8 +12,9 @@ class QueryTest < Minitest::Test | ||
12 | end | 12 | end |
13 | 13 | ||
14 | def test_with_effective_min_score | 14 | def test_with_effective_min_score |
15 | + min_score = elasticsearch_below50? ? 0.1 : 1 | ||
15 | store_names ["Milk", "Milk2"] | 16 | store_names ["Milk", "Milk2"] |
16 | - assert_search "milk", ["Milk"], body_options: {min_score: 0.1} | 17 | + assert_search "milk", ["Milk"], body_options: {min_score: min_score} |
17 | end | 18 | end |
18 | 19 | ||
19 | def test_with_uneffective_min_score | 20 | def test_with_uneffective_min_score |
test/sql_test.rb
@@ -163,6 +163,7 @@ class SqlTest < Minitest::Test | @@ -163,6 +163,7 @@ class SqlTest < Minitest::Test | ||
163 | end | 163 | end |
164 | 164 | ||
165 | def test_select_v2_include | 165 | def test_select_v2_include |
166 | + skip unless elasticsearch_below50? | ||
166 | store [{name: "Product A", user_ids: [1, 2]}] | 167 | store [{name: "Product A", user_ids: [1, 2]}] |
167 | result = Product.search("product", load: false, select_v2: {include: [:name]}).first | 168 | result = Product.search("product", load: false, select_v2: {include: [:name]}).first |
168 | assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort | 169 | assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort |
@@ -171,6 +172,7 @@ class SqlTest < Minitest::Test | @@ -171,6 +172,7 @@ class SqlTest < Minitest::Test | ||
171 | end | 172 | end |
172 | 173 | ||
173 | def test_select_v2_exclude | 174 | def test_select_v2_exclude |
175 | + skip unless elasticsearch_below50? | ||
174 | store [{name: "Product A", user_ids: [1, 2], store_id: 1}] | 176 | store [{name: "Product A", user_ids: [1, 2], store_id: 1}] |
175 | result = Product.search("product", load: false, select_v2: {exclude: [:name]}).first | 177 | result = Product.search("product", load: false, select_v2: {exclude: [:name]}).first |
176 | assert_nil result.name | 178 | assert_nil result.name |
@@ -179,6 +181,7 @@ class SqlTest < Minitest::Test | @@ -179,6 +181,7 @@ class SqlTest < Minitest::Test | ||
179 | end | 181 | end |
180 | 182 | ||
181 | def test_select_v2_include_and_exclude | 183 | def test_select_v2_include_and_exclude |
184 | + skip unless elasticsearch_below50? | ||
182 | # let's take this to the next level | 185 | # let's take this to the next level |
183 | store [{name: "Product A", user_ids: [1, 2], store_id: 1}] | 186 | store [{name: "Product A", user_ids: [1, 2], store_id: 1}] |
184 | result = Product.search("product", load: false, select_v2: {include: [:store_id], exclude: [:name]}).first | 187 | result = Product.search("product", load: false, select_v2: {include: [:store_id], exclude: [:name]}).first |
@@ -187,6 +190,34 @@ class SqlTest < Minitest::Test | @@ -187,6 +190,34 @@ class SqlTest < Minitest::Test | ||
187 | assert_nil result.user_ids | 190 | assert_nil result.user_ids |
188 | end | 191 | end |
189 | 192 | ||
193 | + def test_select_v2_includes | ||
194 | + skip if elasticsearch_below50? | ||
195 | + store [{name: "Product A", user_ids: [1, 2]}] | ||
196 | + result = Product.search("product", load: false, select_v2: {includes: [:name]}).first | ||
197 | + assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort | ||
198 | + assert_equal "Product A", result.name | ||
199 | + assert_nil result.store_id | ||
200 | + end | ||
201 | + | ||
202 | + def test_select_v2_excludes | ||
203 | + skip if elasticsearch_below50? | ||
204 | + store [{name: "Product A", user_ids: [1, 2], store_id: 1}] | ||
205 | + result = Product.search("product", load: false, select_v2: {excludes: [:name]}).first | ||
206 | + assert_nil result.name | ||
207 | + assert_equal [1, 2], result.user_ids | ||
208 | + assert_equal 1, result.store_id | ||
209 | + end | ||
210 | + | ||
211 | + def test_select_v2_include_and_excludes | ||
212 | + skip if elasticsearch_below50? | ||
213 | + # let's take this to the next level | ||
214 | + store [{name: "Product A", user_ids: [1, 2], store_id: 1}] | ||
215 | + result = Product.search("product", load: false, select_v2: {includes: [:store_id], excludes: [:name]}).first | ||
216 | + assert_equal 1, result.store_id | ||
217 | + assert_nil result.name | ||
218 | + assert_nil result.user_ids | ||
219 | + end | ||
220 | + | ||
190 | # other tests | 221 | # other tests |
191 | 222 | ||
192 | def test_nested_object | 223 | def test_nested_object |