Skip to content

Commit

Permalink
Fix aggregation to respect index param (#209)
Browse files Browse the repository at this point in the history
Fix issue where the `index` parameter was being ignored when using `response_type => aggregations`

Fixed: #208
---------

Co-authored-by: Ry Biesemeyer <[email protected]>
  • Loading branch information
kaisecheng and yaauie authored Aug 23, 2024
1 parent f6a5b65 commit ef8874c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion lib/logstash/inputs/elasticsearch/aggregation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion logstash-input-elasticsearch.gemspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 4 additions & 2 deletions spec/inputs/elasticsearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ef8874c

Please sign in to comment.