Commit 84eea3b10ef40f135eb463bc1317a3bff3a5ed8a

Authored by Andrew Kane
1 parent 2e6c82a1

Added support for Elasticsearch 5.0 beta

.travis.yml
... ... @@ -34,7 +34,7 @@ matrix:
34 34 - gemfile: Gemfile
35 35 env: ELASTICSEARCH_VERSION=2.0.0
36 36 - gemfile: Gemfile
37   - env: ELASTICSEARCH_VERSION=5.0.0-alpha5
  37 + env: ELASTICSEARCH_VERSION=5.0.0-beta1
38 38 # - gemfile: test/gemfiles/nobrainer.gemfile
39 39 # env: NOBRAINER=true
40 40 allow_failures:
... ...
CHANGELOG.md
1 1 ## 1.3.5 [unreleased]
2 2  
  3 +- Added support for Elasticsearch 5.0 beta
3 4 - Added `request_params` option
4 5 - Added `filterable` option
5 6  
... ...
lib/searchkick/query.rb
... ... @@ -384,13 +384,22 @@ module Searchkick
384 384 payload[:fields] = options[:select] if options[:select] != true
385 385 elsif options[:select_v2]
386 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 393 else
389 394 payload[:_source] = options[:select_v2]
390 395 end
391 396 elsif load
392 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 403 end
395 404  
396 405 if options[:type] || (klass != searchkick_klass && searchkick_index)
... ...
test/index_test.rb
... ... @@ -112,6 +112,9 @@ class IndexTest < Minitest::Test
112 112 end
113 113  
114 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 118 store [{name: "Product A", alt_description: "Hello"}]
116 119 assert_search "*", [], where: {alt_description: "Hello"}
117 120 end
... ...
test/query_test.rb
... ... @@ -12,8 +12,9 @@ class QueryTest < Minitest::Test
12 12 end
13 13  
14 14 def test_with_effective_min_score
  15 + min_score = elasticsearch_below50? ? 0.1 : 1
15 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 18 end
18 19  
19 20 def test_with_uneffective_min_score
... ...
test/sql_test.rb
... ... @@ -163,6 +163,7 @@ class SqlTest < Minitest::Test
163 163 end
164 164  
165 165 def test_select_v2_include
  166 + skip unless elasticsearch_below50?
166 167 store [{name: "Product A", user_ids: [1, 2]}]
167 168 result = Product.search("product", load: false, select_v2: {include: [:name]}).first
168 169 assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort
... ... @@ -171,6 +172,7 @@ class SqlTest < Minitest::Test
171 172 end
172 173  
173 174 def test_select_v2_exclude
  175 + skip unless elasticsearch_below50?
174 176 store [{name: "Product A", user_ids: [1, 2], store_id: 1}]
175 177 result = Product.search("product", load: false, select_v2: {exclude: [:name]}).first
176 178 assert_nil result.name
... ... @@ -179,6 +181,7 @@ class SqlTest < Minitest::Test
179 181 end
180 182  
181 183 def test_select_v2_include_and_exclude
  184 + skip unless elasticsearch_below50?
182 185 # let's take this to the next level
183 186 store [{name: "Product A", user_ids: [1, 2], store_id: 1}]
184 187 result = Product.search("product", load: false, select_v2: {include: [:store_id], exclude: [:name]}).first
... ... @@ -187,6 +190,34 @@ class SqlTest < Minitest::Test
187 190 assert_nil result.user_ids
188 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 221 # other tests
191 222  
192 223 def test_nested_object
... ...