Commit 4bb79fdb2347e126c69781ccebb5d1ee8851f612
1 parent
da2b7e14
Exists in
master
and in
21 other branches
Force select fields. Add :all value for select.
Showing
2 changed files
with
10 additions
and
3 deletions
Show diff stats
lib/searchkick/query.rb
... | ... | @@ -355,10 +355,10 @@ module Searchkick |
355 | 355 | |
356 | 356 | # An empty array will cause only the _id and _type for each hit to be returned |
357 | 357 | # http://www.elasticsearch.org/guide/reference/api/search/fields/ |
358 | - if load | |
358 | + if options[:select] | |
359 | + payload[:fields] = options[:select] unless options[:select].respond_to?(:to_sym) and options[:select].to_sym == :all | |
360 | + elsif load | |
359 | 361 | payload[:fields] = [] |
360 | - elsif options[:select] | |
361 | - payload[:fields] = options[:select] | |
362 | 362 | end |
363 | 363 | |
364 | 364 | if options[:type] or klass != searchkick_klass | ... | ... |
test/sql_test.rb
... | ... | @@ -298,6 +298,13 @@ class TestSql < Minitest::Test |
298 | 298 | assert_equal [1, 2], result.user_ids |
299 | 299 | end |
300 | 300 | |
301 | + def test_select_all | |
302 | + store [{name: "Product A", user_ids: [1, 2]}] | |
303 | + hit = Product.search("product", select: :all).__send__(:hits).first | |
304 | + assert_equal hit["_source"]["name"], "Product A" | |
305 | + assert_equal hit["_source"]["user_ids"], [1, 2] | |
306 | + end | |
307 | + | |
301 | 308 | def test_nested_object |
302 | 309 | aisle = {"id" => 1, "name" => "Frozen"} |
303 | 310 | store [{name: "Product A", aisle: aisle}] | ... | ... |