From b137164dc33db91b8125afa968b687cfdcdf5b9a Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 5 Dec 2023 14:56:24 +0900 Subject: [PATCH] in_elasticsearch: Avoid to use deprecated endpoint for clear_scroll Signed-off-by: Hiroshi Hatake --- lib/fluent/plugin/in_elasticsearch.rb | 6 +++++- test/plugin/test_in_elasticsearch.rb | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/fluent/plugin/in_elasticsearch.rb b/lib/fluent/plugin/in_elasticsearch.rb index 032fc12..83df64a 100644 --- a/lib/fluent/plugin/in_elasticsearch.rb +++ b/lib/fluent/plugin/in_elasticsearch.rb @@ -286,7 +286,11 @@ def run_slice(slice_id=nil) end router.emit_stream(@tag, es) - client.clear_scroll(scroll_id: scroll_id) if scroll_id + if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("7.0.0") + client.clear_scroll(body: {scroll_id: scroll_id}) if scroll_id + else + client.clear_scroll(scroll_id: scroll_id) if scroll_id + end end def process_scroll_request(scroll_id) diff --git a/test/plugin/test_in_elasticsearch.rb b/test/plugin/test_in_elasticsearch.rb index d867bc0..2977ad9 100644 --- a/test/plugin/test_in_elasticsearch.rb +++ b/test/plugin/test_in_elasticsearch.rb @@ -463,9 +463,14 @@ def test_emit_with_size headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'}} end end) - stub_request(:delete, "http://localhost:9200/_search/scroll/WomkoUKG0QPB679Ulo6TqQgh3pIGRUmrl9qXXGK3EeiQh9rbYNasTkspZQcJ01uz"). + if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("7.0.0") + stub_request(:delete, "http://localhost:9200/_search/scroll"). + with(body: "{\"scroll_id\":\"WomkoUKG0QPB679Ulo6TqQgh3pIGRUmrl9qXXGK3EeiQh9rbYNasTkspZQcJ01uz\"}"). to_return(status: 200, body: "", headers: {}) - + else + stub_request(:delete, "http://localhost:9200/_search/scroll/WomkoUKG0QPB679Ulo6TqQgh3pIGRUmrl9qXXGK3EeiQh9rbYNasTkspZQcJ01uz"). + to_return(status: 200, body: "", headers: {}) + end driver(CONFIG + %[size 1]) driver.run(expect_emits: 1, timeout: 10) expected = [