[PATCH compass-ci] es_query.rb: fix _scroll_id change

[why] _scroll_id will change every time query, so you need to save the last _scroll_id. Signed-off-by: Cui Yili <2268260388@qq.com> --- lib/es_query.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/es_query.rb b/lib/es_query.rb index 22d68a9..6bd39bf 100644 --- a/lib/es_query.rb +++ b/lib/es_query.rb @@ -47,11 +47,12 @@ class ESQuery }, size: size } result = @client.search index: @index, scroll: '10m', body: query - @scroll_id = result['_scroll_id'] - return result else - @client.scroll scroll: '10m', scroll_id: @scroll_id + result = @client.scroll scroll: '10m', scroll_id: @scroll_id end + + @scroll_id = result['_scroll_id'] unless result.empty? + return result end def query_by_id(id) -- 2.23.0

On Sat, Apr 17, 2021 at 12:00:25PM +0800, Cui Yili wrote:
[why] _scroll_id will change every time query, so you need to save the last _scroll_id.
Signed-off-by: Cui Yili <2268260388@qq.com> --- lib/es_query.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/es_query.rb b/lib/es_query.rb index 22d68a9..6bd39bf 100644 --- a/lib/es_query.rb +++ b/lib/es_query.rb @@ -47,11 +47,12 @@ class ESQuery }, size: size } result = @client.search index: @index, scroll: '10m', body: query - @scroll_id = result['_scroll_id'] - return result else - @client.scroll scroll: '10m', scroll_id: @scroll_id + result = @client.scroll scroll: '10m', scroll_id: @scroll_id end + + @scroll_id = result['_scroll_id'] unless result.empty?
^----- should judge whether '_scroll_id' exist again? perhaps like this: @scroll_id = result['_scroll_id'] unless result.empty? && result.include?('_scroll_id') Thanks, Liushaofei
+ return result end
def query_by_id(id) -- 2.23.0
participants (2)
-
Cui Yili
-
Liu Shaofei