logstash-filter-elasticsearch 3.5.0 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57bc6bc825a1866b1ecf39eb35bcab5e062dfb73f7b1e7590feb4fe51358b2c9
4
- data.tar.gz: 48df2bb55103e2fb6196ec8679f1b48ce70742f43dcd9ab3c5ff257637ccdda8
3
+ metadata.gz: d8d5c99d58129ffad85468e4bab7c64f184a0bdc2aa8b8a11c8f52353c8e4876
4
+ data.tar.gz: 30b1a189484e118138d6f7607be7319e035696464e8682b59122f830063b0c8d
5
5
  SHA512:
6
- metadata.gz: e93655c43a05df8d1f7cf261ff552a875cb765111903cf9bc4903e77cb423329f346f1b67d949b6cae24c85872b8ea45a7a08e7ce812d48ab93117d575236eef
7
- data.tar.gz: b3dbca71043c7cbb6ef904e19e30b88dd6e974d92c0fdf77eae52d90c1d41151bdc9b0ef4c9cc93fa8c97937dc31e30c6570a62a8343d693a0b1d00bb2d4fa6a
6
+ metadata.gz: 6ef80c1576cf3d84f3da23bc23ecf7931812675d3566d46a074f6c8901dc182a34a67da8c17f7a6beafd33407c81d4a392c8d604b54abbaad3e542dd2260b987
7
+ data.tar.gz: 7b754511d4a252de292646d67929b067d4fc44d7eabad53fb300098320592292fc0afac1d200737e6203fe7bd7422a9a1ea7b43e028d1d194879adb7a39788fb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.6.0
2
+ - Add support for extracting hits total from Elasticsearch 7.x responses
3
+
1
4
  ## 3.5.0
2
5
  - Added connection check during register to avoid failures during processing
3
6
  - Changed Elasticsearch Client transport to use Manticore
@@ -94,7 +94,7 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
94
94
  results = get_client.search(params)
95
95
  raise "Elasticsearch query error: #{results["_shards"]["failures"]}" if results["_shards"].include? "failures"
96
96
 
97
- event.set("[@metadata][total_hits]", results['hits']['total'])
97
+ event.set("[@metadata][total_hits]", extract_total_from_hits(results['hits']))
98
98
 
99
99
  resultsHits = results["hits"]["hits"]
100
100
  if !resultsHits.nil? && !resultsHits.empty?
@@ -173,6 +173,21 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
173
173
  end
174
174
  end
175
175
 
176
+ # Given a "hits" object from an Elasticsearch response, return the total number of hits in
177
+ # the result set.
178
+ # @param hits [Hash{String=>Object}]
179
+ # @return [Integer]
180
+ def extract_total_from_hits(hits)
181
+ total = hits['total']
182
+
183
+ # Elasticsearch 7.x produces an object containing `value` and `relation` in order
184
+ # to enable unambiguous reporting when the total is only a lower bound; if we get
185
+ # an object back, return its `value`.
186
+ return total['value'] if total.kind_of?(Hash)
187
+
188
+ total
189
+ end
190
+
176
191
  def test_connection!
177
192
  get_client.client.ping
178
193
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-elasticsearch'
4
- s.version = '3.5.0'
4
+ s.version = '3.6.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Copies fields from previous log events in Elasticsearch to current events "
7
7
  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"
@@ -113,6 +113,26 @@ describe LogStash::Filters::Elasticsearch do
113
113
  end
114
114
  end
115
115
 
116
+ context 'when Elasticsearch 7.x gives us a totals object instead of an integer' do
117
+ let(:config) do
118
+ {
119
+ "hosts" => ["localhost:9200"],
120
+ "query" => "response: 404",
121
+ "fields" => { "response" => "code" },
122
+ "result_size" => 10
123
+ }
124
+ end
125
+
126
+ let(:response) do
127
+ LogStash::Json.load(File.read(File.join(File.dirname(__FILE__), "fixtures", "elasticsearch_7.x_hits_total_as_object.json")))
128
+ end
129
+
130
+ it "should enhance the current event with new data" do
131
+ plugin.filter(event)
132
+ expect(event.get("[@metadata][total_hits]")).to eq(13476)
133
+ end
134
+ end
135
+
116
136
  context "if something wrong happen during connection" do
117
137
 
118
138
  before(:each) do
@@ -0,0 +1,70 @@
1
+ {
2
+ "took": 49,
3
+ "timed_out": false,
4
+ "_shards": {
5
+ "total": 155,
6
+ "successful": 155,
7
+ "failed": 0
8
+ },
9
+ "hits": {
10
+ "total": {
11
+ "value": 13476,
12
+ "relation": "eq"
13
+ },
14
+ "max_score": 1,
15
+ "hits": [{
16
+ "_index": "logstash-2014.08.26",
17
+ "_type": "logs",
18
+ "_id": "AVVY76L_AW7v0kX8KXo4",
19
+ "_score": 1,
20
+ "_source": {
21
+ "request": "/doc/index.html?org/elasticsearch/action/search/SearchResponse.html",
22
+ "agent": "\"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)\"",
23
+ "geoip": {
24
+ "timezone": "America/Los_Angeles",
25
+ "ip": "66.249.73.185",
26
+ "latitude": 37.386,
27
+ "continent_code": "NA",
28
+ "city_name": "Mountain View",
29
+ "country_code2": "US",
30
+ "country_name": "United States",
31
+ "dma_code": 807,
32
+ "country_code3": "US",
33
+ "region_name": "California",
34
+ "location": [-122.0838,
35
+ 37.386
36
+ ],
37
+ "postal_code": "94035",
38
+ "longitude": -122.0838,
39
+ "region_code": "CA"
40
+ },
41
+ "auth": "-",
42
+ "ident": "-",
43
+ "verb": "GET",
44
+ "useragent": {
45
+ "os": "Other",
46
+ "major": "2",
47
+ "minor": "1",
48
+ "name": "Googlebot",
49
+ "os_name": "Other",
50
+ "device": "Spider"
51
+ },
52
+ "message": "66.249.73.185 - - [26/Aug/2014:21:22:13 +0000] \"GET /doc/index.html?org/elasticsearch/action/search/SearchResponse.html HTTP/1.1\" 404 294 \"-\" \"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)\"",
53
+ "referrer": "\"-\"",
54
+ "@timestamp": "2014-08-26T21:22:13.000Z",
55
+ "response": 404,
56
+ "bytes": 294,
57
+ "clientip": "66.249.73.185",
58
+ "@version": "1",
59
+ "host": "skywalker",
60
+ "httpversion": "1.1",
61
+ "timestamp": "26/Aug/2014:21:22:13 +0000"
62
+ }
63
+ }]
64
+ },
65
+ "aggregations": {
66
+ "bytes_avg": {
67
+ "value": 294
68
+ }
69
+ }
70
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-22 00:00:00.000000000 Z
11
+ date: 2018-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +97,7 @@ files:
97
97
  - lib/logstash/filters/elasticsearch/client.rb
98
98
  - logstash-filter-elasticsearch.gemspec
99
99
  - spec/filters/elasticsearch_spec.rb
100
+ - spec/filters/fixtures/elasticsearch_7.x_hits_total_as_object.json
100
101
  - spec/filters/fixtures/query_template.json
101
102
  - spec/filters/fixtures/request_error.json
102
103
  - spec/filters/fixtures/request_size0_agg.json
@@ -131,6 +132,7 @@ specification_version: 4
131
132
  summary: Copies fields from previous log events in Elasticsearch to current events
132
133
  test_files:
133
134
  - spec/filters/elasticsearch_spec.rb
135
+ - spec/filters/fixtures/elasticsearch_7.x_hits_total_as_object.json
134
136
  - spec/filters/fixtures/query_template.json
135
137
  - spec/filters/fixtures/request_error.json
136
138
  - spec/filters/fixtures/request_size0_agg.json