Commit 1bd814e825756a562631db740335d0b07e1e8a1b

Authored by Andrew Kane
1 parent b9a903c0

Added search timeout to payload - cc @elguapo1611

  1 +## 1.3.4 [unreleased]
  2 +
  3 +- Added search timeout to payload
  4 +
1 ## 1.3.3 5 ## 1.3.3
2 6
3 - Fix for namespaced models (broken in 1.3.2) 7 - Fix for namespaced models (broken in 1.3.2)
lib/searchkick/query.rb
@@ -368,6 +368,9 @@ module Searchkick @@ -368,6 +368,9 @@ module Searchkick
368 # highlight 368 # highlight
369 set_highlights(payload, fields) if options[:highlight] 369 set_highlights(payload, fields) if options[:highlight]
370 370
  371 + # timeout shortly after client times out
  372 + payload[:timeout] ||= "#{Searchkick.search_timeout + 1}s"
  373 +
371 # An empty array will cause only the _id and _type for each hit to be returned 374 # An empty array will cause only the _id and _type for each hit to be returned
372 # doc for :select - http://www.elasticsearch.org/guide/reference/api/search/fields/ 375 # doc for :select - http://www.elasticsearch.org/guide/reference/api/search/fields/
373 # doc for :select_v2 - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html 376 # doc for :select_v2 - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html
test/query_test.rb
@@ -20,4 +20,12 @@ class QueryTest < Minitest::Test @@ -20,4 +20,12 @@ class QueryTest < Minitest::Test
20 store_names ["Milk", "Milk2"] 20 store_names ["Milk", "Milk2"]
21 assert_equal ["Milk", "Milk2"], Product.search("Milk", body_options: { min_score: 0.0001 }).map(&:name) 21 assert_equal ["Milk", "Milk2"], Product.search("Milk", body_options: { min_score: 0.0001 }).map(&:name)
22 end 22 end
  23 +
  24 + def test_default_timeout
  25 + assert_equal "6s", Product.search("*", execute: false).body[:timeout]
  26 + end
  27 +
  28 + def test_timeout_override
  29 + assert_equal "1s", Product.search("*", body_options: {timeout: "1s"}, execute: false).body[:timeout]
  30 + end
23 end 31 end