diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 1491b12..f943376 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -864,10 +864,11 @@ module Searchkick } end - # TODO id transformation for arrays def set_order(payload) order = options[:order].is_a?(Enumerable) ? options[:order] : {options[:order] => :asc} id_field = :_id + # TODO no longer map id to _id in Searchkick 5 + # since sorting on _id is deprecated in Elasticsearch payload[:sort] = order.is_a?(Array) ? order : Hash[order.map { |k, v| [k.to_s == "id" ? id_field : k, v] }] end diff --git a/test/order_test.rb b/test/order_test.rb index 4bfdacc..d49ecc8 100644 --- a/test/order_test.rb +++ b/test/order_test.rb @@ -11,13 +11,18 @@ class OrderTest < Minitest::Test assert_order "product", ["Product A", "Product B", "Product C", "Product D"], order: "name" end + # TODO no longer map id to _id in Searchkick 5 + # since sorting on _id is deprecated in Elasticsearch def test_id skip if cequel? store_names ["Product A", "Product B"] product_a = Product.where(name: "Product A").first product_b = Product.where(name: "Product B").first - assert_order "product", [product_a, product_b].sort_by { |r| r.id.to_s }.map(&:name), order: {id: :asc} + _, stderr = capture_io do + assert_order "product", [product_a, product_b].sort_by { |r| r.id.to_s }.map(&:name), order: {id: :asc} + end + assert_match "Loading the fielddata on the _id field is deprecated", stderr end def test_multiple @@ -30,6 +35,7 @@ class OrderTest < Minitest::Test end def test_unmapped_type + Product.search_index.refresh assert_order "product", [], order: {not_mapped: {unmapped_type: "long"}} end -- libgit2 0.21.0