From ef8874c3339c6c7e06f93e47e40fa80064dfeb7f Mon Sep 17 00:00:00 2001 From: kaisecheng <69120390+kaisecheng@users.noreply.github.com> Date: Fri, 23 Aug 2024 01:04:39 +0100 Subject: [PATCH] Fix aggregation to respect `index` param (#209) Fix issue where the `index` parameter was being ignored when using `response_type => aggregations` Fixed: #208 --------- Co-authored-by: Ry Biesemeyer --- .travis.yml | 2 -- CHANGELOG.md | 3 +++ lib/logstash/inputs/elasticsearch/aggregation.rb | 2 +- logstash-input-elasticsearch.gemspec | 2 +- spec/inputs/elasticsearch_spec.rb | 6 ++++-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1ba5da9..0ed7bab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,8 @@ env: - INTEGRATION=false ELASTIC_STACK_VERSION=8.x - INTEGRATION=false ELASTIC_STACK_VERSION=7.x SNAPSHOT=true - INTEGRATION=false ELASTIC_STACK_VERSION=8.x SNAPSHOT=true -- INTEGRATION=false ELASTIC_STACK_VERSION=7.16.3 MANTICORE_VERSION=0.7.1 ELASTICSEARCH_VERSION=7.15.0 - INTEGRATION=true ELASTIC_STACK_VERSION=7.x - INTEGRATION=true ELASTIC_STACK_VERSION=7.x SNAPSHOT=true LOG_LEVEL=info - INTEGRATION=true ELASTIC_STACK_VERSION=8.x SNAPSHOT=true LOG_LEVEL=info - SECURE_INTEGRATION=true INTEGRATION=true ELASTIC_STACK_VERSION=7.x LOG_LEVEL=info - SECURE_INTEGRATION=true INTEGRATION=true ELASTIC_STACK_VERSION=7.x ES_SSL_SUPPORTED_PROTOCOLS=TLSv1.3 -- SECURE_INTEGRATION=true INTEGRATION=true ELASTIC_STACK_VERSION=7.16.3 MANTICORE_VERSION=0.7.1 ELASTICSEARCH_VERSION=7.14.1 LOG_LEVEL=info diff --git a/CHANGELOG.md b/CHANGELOG.md index d6190ad..8a3fe7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 4.20.4 + - Fix issue where the `index` parameter was being ignored when using `response_type => aggregations` [#209](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/209) + ## 4.20.3 - [DOC] Update link to bypass redirect, resolving directly to correct content [#206](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/206) diff --git a/lib/logstash/inputs/elasticsearch/aggregation.rb b/lib/logstash/inputs/elasticsearch/aggregation.rb index 0855cb8..e74a435 100644 --- a/lib/logstash/inputs/elasticsearch/aggregation.rb +++ b/lib/logstash/inputs/elasticsearch/aggregation.rb @@ -16,7 +16,7 @@ def initialize(client, plugin) @query = @plugin_params["query"] @retries = @plugin_params["retries"] @agg_options = { - :index => @index, + :index => @plugin_params["index"], :size => 0 }.merge(:body => @query) diff --git a/logstash-input-elasticsearch.gemspec b/logstash-input-elasticsearch.gemspec index 93f5fbc..ed79adc 100644 --- a/logstash-input-elasticsearch.gemspec +++ b/logstash-input-elasticsearch.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'logstash-input-elasticsearch' - s.version = '4.20.3' + s.version = '4.20.4' s.licenses = ['Apache License (2.0)'] s.summary = "Reads query results from an Elasticsearch cluster" s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program" diff --git a/spec/inputs/elasticsearch_spec.rb b/spec/inputs/elasticsearch_spec.rb index 21b9509..652c299 100644 --- a/spec/inputs/elasticsearch_spec.rb +++ b/spec/inputs/elasticsearch_spec.rb @@ -1036,12 +1036,14 @@ def wait_receive_request end context "aggregations" do + let(:index_name) { "rainbow" } let(:config) do { 'hosts' => ["localhost"], 'query' => '{ "query": {}, "size": 0, "aggs":{"total_count": { "value_count": { "field": "type" }}, "empty_count": { "sum": { "field": "_meta.empty_event" }}}}', 'response_type' => 'aggregations', - 'size' => 0 + 'size' => 0, + 'index' => index_name } end @@ -1080,7 +1082,7 @@ def wait_receive_request before { plugin.register } it 'creates the events from the aggregations' do - expect(client).to receive(:search).with(any_args).and_return(mock_response) + expect(client).to receive(:search).with(hash_including(:body => anything, :size => 0, :index => index_name)).and_return(mock_response) plugin.run queue event = queue.pop