From 295f43baa5842f0e3c0da56e38f00759f7f066b3 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 4 Jun 2019 16:54:44 -0700 Subject: [PATCH] Added clear_scroll method --- CHANGELOG.md | 1 + lib/searchkick/results.rb | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa173bb..92e63c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 4.0.2 [unreleased] - Added block form of `scroll` +- Added `clear_scroll` method - Fixed custom mappings ## 4.0.1 diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb index cd4e9e8..f78ae84 100644 --- a/lib/searchkick/results.rb +++ b/lib/searchkick/results.rb @@ -235,14 +235,7 @@ module Searchkick records = records.scroll end - begin - # try to clear scroll - # not required as scroll will expire - # but there is a cost to open scrolls - Searchkick.client.clear_scroll(scroll_id: scroll_id) - rescue Elasticsearch::Transport::Transport::Error - # okay if it fails - end + records.clear_scroll else params = { scroll: options[:scroll], @@ -262,6 +255,17 @@ module Searchkick end end + def clear_scroll + begin + # try to clear scroll + # not required as scroll will expire + # but there is a cost to open scrolls + Searchkick.client.clear_scroll(scroll_id: scroll_id) + rescue Elasticsearch::Transport::Transport::Error + # do nothing + end + end + private def results_query(records, hits) -- libgit2 0.21.0