logstash-output-elasticsearch 10.8.6-java → 11.0.3-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/docs/index.asciidoc +132 -22
  4. data/lib/logstash/outputs/elasticsearch.rb +125 -64
  5. data/lib/logstash/outputs/elasticsearch/data_stream_support.rb +233 -0
  6. data/lib/logstash/outputs/elasticsearch/http_client.rb +9 -7
  7. data/lib/logstash/outputs/elasticsearch/http_client/pool.rb +49 -62
  8. data/lib/logstash/outputs/elasticsearch/ilm.rb +13 -45
  9. data/lib/logstash/outputs/elasticsearch/license_checker.rb +26 -23
  10. data/lib/logstash/outputs/elasticsearch/template_manager.rb +4 -6
  11. data/lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-8x.json +1 -0
  12. data/lib/logstash/plugin_mixins/elasticsearch/api_configs.rb +157 -153
  13. data/lib/logstash/plugin_mixins/elasticsearch/common.rb +71 -58
  14. data/logstash-output-elasticsearch.gemspec +3 -3
  15. data/spec/es_spec_helper.rb +7 -12
  16. data/spec/fixtures/_nodes/{5x_6x.json → 6x.json} +5 -5
  17. data/spec/integration/outputs/compressed_indexing_spec.rb +47 -46
  18. data/spec/integration/outputs/data_stream_spec.rb +61 -0
  19. data/spec/integration/outputs/delete_spec.rb +49 -51
  20. data/spec/integration/outputs/ilm_spec.rb +236 -248
  21. data/spec/integration/outputs/index_spec.rb +5 -2
  22. data/spec/integration/outputs/index_version_spec.rb +78 -82
  23. data/spec/integration/outputs/ingest_pipeline_spec.rb +58 -58
  24. data/spec/integration/outputs/painless_update_spec.rb +74 -164
  25. data/spec/integration/outputs/parent_spec.rb +67 -75
  26. data/spec/integration/outputs/retry_spec.rb +6 -6
  27. data/spec/integration/outputs/sniffer_spec.rb +15 -54
  28. data/spec/integration/outputs/templates_spec.rb +79 -81
  29. data/spec/integration/outputs/update_spec.rb +99 -101
  30. data/spec/spec_helper.rb +10 -0
  31. data/spec/unit/outputs/elasticsearch/data_stream_support_spec.rb +528 -0
  32. data/spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb +1 -0
  33. data/spec/unit/outputs/elasticsearch/http_client/pool_spec.rb +36 -29
  34. data/spec/unit/outputs/elasticsearch/http_client_spec.rb +2 -3
  35. data/spec/unit/outputs/elasticsearch/template_manager_spec.rb +10 -12
  36. data/spec/unit/outputs/elasticsearch_proxy_spec.rb +1 -2
  37. data/spec/unit/outputs/elasticsearch_spec.rb +176 -41
  38. data/spec/unit/outputs/elasticsearch_ssl_spec.rb +1 -2
  39. data/spec/unit/outputs/error_whitelist_spec.rb +3 -2
  40. data/spec/unit/outputs/license_check_spec.rb +0 -16
  41. metadata +29 -36
  42. data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-2x.json +0 -95
  43. data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-5x.json +0 -46
  44. data/spec/fixtures/_nodes/2x_1x.json +0 -27
  45. data/spec/fixtures/scripts/groovy/scripted_update.groovy +0 -2
  46. data/spec/fixtures/scripts/groovy/scripted_update_nested.groovy +0 -2
  47. data/spec/fixtures/scripts/groovy/scripted_upsert.groovy +0 -2
  48. data/spec/integration/outputs/groovy_update_spec.rb +0 -150
  49. data/spec/integration/outputs/templates_5x_spec.rb +0 -98
@@ -1,6 +1,5 @@
1
- require_relative "../../../spec/es_spec_helper"
1
+ require_relative "../../../spec/spec_helper"
2
2
  require 'stud/temporary'
3
- require "logstash/outputs/elasticsearch"
4
3
 
5
4
  describe "SSL option" do
6
5
  let(:manticore_double) { double("manticoreSSL #{self.inspect}") }
@@ -12,6 +12,7 @@ describe "whitelisting error types in expected behavior" do
12
12
  before :each do
13
13
  allow(subject.logger).to receive(:warn)
14
14
  allow(subject).to receive(:maximum_seen_major_version).and_return(0)
15
+ allow(subject).to receive(:finish_register)
15
16
 
16
17
  subject.register
17
18
 
@@ -39,7 +40,7 @@ describe "whitelisting error types in expected behavior" do
39
40
 
40
41
  describe "when failure logging is enabled for everything" do
41
42
  it "should log a failure on the action" do
42
- expect(subject.logger).to have_received(:warn).with("Failed action.", anything)
43
+ expect(subject.logger).to have_received(:warn).with("Failed action", anything)
43
44
  end
44
45
  end
45
46
 
@@ -47,7 +48,7 @@ describe "whitelisting error types in expected behavior" do
47
48
  let(:settings) { super().merge("failure_type_logging_whitelist" => ["document_already_exists_exception"]) }
48
49
 
49
50
  it "should log a failure on the action" do
50
- expect(subject.logger).not_to have_received(:warn).with("Failed action.", anything)
51
+ expect(subject.logger).not_to have_received(:warn).with("Failed action", anything)
51
52
  end
52
53
  end
53
54
 
@@ -14,22 +14,6 @@ describe LogStash::Outputs::ElasticSearch::LicenseChecker do
14
14
  end
15
15
  end
16
16
 
17
- context "LicenseChecker API required by Pool specs" do
18
- subject { described_class }
19
-
20
- it "defines the oss? method" do
21
- expect(subject.instance_methods).to include(:oss?)
22
- end
23
-
24
- it "defines the valid_es_license? method" do
25
- expect(subject.instance_methods).to include(:valid_es_license?)
26
- end
27
-
28
- it "defines the log_license_deprecation_warn method" do
29
- expect(subject.instance_methods).to include(:log_license_deprecation_warn)
30
- end
31
- end
32
-
33
17
  context "Pool class API required by the LicenseChecker" do
34
18
  subject { LogStash::Outputs::ElasticSearch::HttpClient::Pool }
35
19
 
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.8.6
4
+ version: 11.0.3
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-06 00:00:00.000000000 Z
11
+ date: 2021-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.5.4
18
+ version: 0.7.1
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: 1.0.0
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.5.4
29
+ version: 0.7.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.0.0
@@ -50,20 +50,6 @@ dependencies:
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0.0'
53
- - !ruby/object:Gem::Dependency
54
- requirement: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - "~>"
57
- - !ruby/object:Gem::Version
58
- version: '0.6'
59
- name: cabin
60
- prerelease: false
61
- type: :runtime
62
- version_requirements: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '0.6'
67
53
  - !ruby/object:Gem::Dependency
68
54
  requirement: !ruby/object:Gem::Requirement
69
55
  requirements:
@@ -140,6 +126,20 @@ dependencies:
140
126
  - - ">="
141
127
  - !ruby/object:Gem::Version
142
128
  version: '0'
129
+ - !ruby/object:Gem::Dependency
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: '0.6'
135
+ name: cabin
136
+ prerelease: false
137
+ type: :development
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: '0.6'
143
143
  - !ruby/object:Gem::Dependency
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  requirements:
@@ -170,6 +170,7 @@ files:
170
170
  - README.md
171
171
  - docs/index.asciidoc
172
172
  - lib/logstash/outputs/elasticsearch.rb
173
+ - lib/logstash/outputs/elasticsearch/data_stream_support.rb
173
174
  - lib/logstash/outputs/elasticsearch/default-ilm-policy.json
174
175
  - lib/logstash/outputs/elasticsearch/http_client.rb
175
176
  - lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb
@@ -178,26 +179,21 @@ files:
178
179
  - lib/logstash/outputs/elasticsearch/ilm.rb
179
180
  - lib/logstash/outputs/elasticsearch/license_checker.rb
180
181
  - lib/logstash/outputs/elasticsearch/template_manager.rb
181
- - lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-2x.json
182
- - lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-5x.json
183
182
  - lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-6x.json
184
183
  - lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-7x.json
185
184
  - lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-8x.json
186
185
  - lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-6x.json
187
186
  - lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-7x.json
187
+ - lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-8x.json
188
188
  - lib/logstash/plugin_mixins/elasticsearch/api_configs.rb
189
189
  - lib/logstash/plugin_mixins/elasticsearch/common.rb
190
190
  - lib/logstash/plugin_mixins/elasticsearch/noop_license_checker.rb
191
191
  - logstash-output-elasticsearch.gemspec
192
192
  - spec/es_spec_helper.rb
193
- - spec/fixtures/_nodes/2x_1x.json
194
- - spec/fixtures/_nodes/5x_6x.json
193
+ - spec/fixtures/_nodes/6x.json
195
194
  - spec/fixtures/_nodes/7x.json
196
195
  - spec/fixtures/htpasswd
197
196
  - spec/fixtures/nginx_reverse_proxy.conf
198
- - spec/fixtures/scripts/groovy/scripted_update.groovy
199
- - spec/fixtures/scripts/groovy/scripted_update_nested.groovy
200
- - spec/fixtures/scripts/groovy/scripted_upsert.groovy
201
197
  - spec/fixtures/scripts/painless/scripted_update.painless
202
198
  - spec/fixtures/scripts/painless/scripted_update_nested.painless
203
199
  - spec/fixtures/scripts/painless/scripted_upsert.painless
@@ -210,8 +206,8 @@ files:
210
206
  - spec/fixtures/test_certs/test.key
211
207
  - spec/integration/outputs/compressed_indexing_spec.rb
212
208
  - spec/integration/outputs/create_spec.rb
209
+ - spec/integration/outputs/data_stream_spec.rb
213
210
  - spec/integration/outputs/delete_spec.rb
214
- - spec/integration/outputs/groovy_update_spec.rb
215
211
  - spec/integration/outputs/ilm_spec.rb
216
212
  - spec/integration/outputs/index_spec.rb
217
213
  - spec/integration/outputs/index_version_spec.rb
@@ -223,15 +219,16 @@ files:
223
219
  - spec/integration/outputs/retry_spec.rb
224
220
  - spec/integration/outputs/routing_spec.rb
225
221
  - spec/integration/outputs/sniffer_spec.rb
226
- - spec/integration/outputs/templates_5x_spec.rb
227
222
  - spec/integration/outputs/templates_spec.rb
228
223
  - spec/integration/outputs/update_spec.rb
224
+ - spec/spec_helper.rb
229
225
  - spec/support/elasticsearch/api/actions/delete_ilm_policy.rb
230
226
  - spec/support/elasticsearch/api/actions/get_alias.rb
231
227
  - spec/support/elasticsearch/api/actions/get_ilm_policy.rb
232
228
  - spec/support/elasticsearch/api/actions/put_alias.rb
233
229
  - spec/support/elasticsearch/api/actions/put_ilm_policy.rb
234
230
  - spec/unit/http_client_builder_spec.rb
231
+ - spec/unit/outputs/elasticsearch/data_stream_support_spec.rb
235
232
  - spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb
236
233
  - spec/unit/outputs/elasticsearch/http_client/pool_spec.rb
237
234
  - spec/unit/outputs/elasticsearch/http_client_spec.rb
@@ -262,21 +259,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
259
  - !ruby/object:Gem::Version
263
260
  version: '0'
264
261
  requirements: []
265
- rubyforge_project:
266
- rubygems_version: 2.6.13
262
+ rubygems_version: 3.1.6
267
263
  signing_key:
268
264
  specification_version: 4
269
265
  summary: Stores logs in Elasticsearch
270
266
  test_files:
271
267
  - spec/es_spec_helper.rb
272
- - spec/fixtures/_nodes/2x_1x.json
273
- - spec/fixtures/_nodes/5x_6x.json
268
+ - spec/fixtures/_nodes/6x.json
274
269
  - spec/fixtures/_nodes/7x.json
275
270
  - spec/fixtures/htpasswd
276
271
  - spec/fixtures/nginx_reverse_proxy.conf
277
- - spec/fixtures/scripts/groovy/scripted_update.groovy
278
- - spec/fixtures/scripts/groovy/scripted_update_nested.groovy
279
- - spec/fixtures/scripts/groovy/scripted_upsert.groovy
280
272
  - spec/fixtures/scripts/painless/scripted_update.painless
281
273
  - spec/fixtures/scripts/painless/scripted_update_nested.painless
282
274
  - spec/fixtures/scripts/painless/scripted_upsert.painless
@@ -289,8 +281,8 @@ test_files:
289
281
  - spec/fixtures/test_certs/test.key
290
282
  - spec/integration/outputs/compressed_indexing_spec.rb
291
283
  - spec/integration/outputs/create_spec.rb
284
+ - spec/integration/outputs/data_stream_spec.rb
292
285
  - spec/integration/outputs/delete_spec.rb
293
- - spec/integration/outputs/groovy_update_spec.rb
294
286
  - spec/integration/outputs/ilm_spec.rb
295
287
  - spec/integration/outputs/index_spec.rb
296
288
  - spec/integration/outputs/index_version_spec.rb
@@ -302,15 +294,16 @@ test_files:
302
294
  - spec/integration/outputs/retry_spec.rb
303
295
  - spec/integration/outputs/routing_spec.rb
304
296
  - spec/integration/outputs/sniffer_spec.rb
305
- - spec/integration/outputs/templates_5x_spec.rb
306
297
  - spec/integration/outputs/templates_spec.rb
307
298
  - spec/integration/outputs/update_spec.rb
299
+ - spec/spec_helper.rb
308
300
  - spec/support/elasticsearch/api/actions/delete_ilm_policy.rb
309
301
  - spec/support/elasticsearch/api/actions/get_alias.rb
310
302
  - spec/support/elasticsearch/api/actions/get_ilm_policy.rb
311
303
  - spec/support/elasticsearch/api/actions/put_alias.rb
312
304
  - spec/support/elasticsearch/api/actions/put_ilm_policy.rb
313
305
  - spec/unit/http_client_builder_spec.rb
306
+ - spec/unit/outputs/elasticsearch/data_stream_support_spec.rb
314
307
  - spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb
315
308
  - spec/unit/outputs/elasticsearch/http_client/pool_spec.rb
316
309
  - spec/unit/outputs/elasticsearch/http_client_spec.rb
@@ -1,95 +0,0 @@
1
- {
2
- "template" : "logstash-*",
3
- "settings" : {
4
- "index.refresh_interval" : "5s"
5
- },
6
- "mappings" : {
7
- "_default_" : {
8
- "_all" : {"enabled" : true, "omit_norms" : true},
9
- "dynamic_templates" : [ {
10
- "message_field" : {
11
- "path_match" : "message",
12
- "match_mapping_type" : "string",
13
- "mapping" : {
14
- "type" : "string", "index" : "analyzed", "omit_norms" : true,
15
- "fielddata" : { "format" : "disabled" }
16
- }
17
- }
18
- }, {
19
- "string_fields" : {
20
- "match" : "*",
21
- "match_mapping_type" : "string",
22
- "mapping" : {
23
- "type" : "string", "index" : "analyzed", "omit_norms" : true,
24
- "fielddata" : { "format" : "disabled" },
25
- "fields" : {
26
- "raw" : {"type": "string", "index" : "not_analyzed", "doc_values" : true, "ignore_above" : 256}
27
- }
28
- }
29
- }
30
- }, {
31
- "float_fields" : {
32
- "match" : "*",
33
- "match_mapping_type" : "float",
34
- "mapping" : { "type" : "float", "doc_values" : true }
35
- }
36
- }, {
37
- "double_fields" : {
38
- "match" : "*",
39
- "match_mapping_type" : "double",
40
- "mapping" : { "type" : "double", "doc_values" : true }
41
- }
42
- }, {
43
- "byte_fields" : {
44
- "match" : "*",
45
- "match_mapping_type" : "byte",
46
- "mapping" : { "type" : "byte", "doc_values" : true }
47
- }
48
- }, {
49
- "short_fields" : {
50
- "match" : "*",
51
- "match_mapping_type" : "short",
52
- "mapping" : { "type" : "short", "doc_values" : true }
53
- }
54
- }, {
55
- "integer_fields" : {
56
- "match" : "*",
57
- "match_mapping_type" : "integer",
58
- "mapping" : { "type" : "integer", "doc_values" : true }
59
- }
60
- }, {
61
- "long_fields" : {
62
- "match" : "*",
63
- "match_mapping_type" : "long",
64
- "mapping" : { "type" : "long", "doc_values" : true }
65
- }
66
- }, {
67
- "date_fields" : {
68
- "match" : "*",
69
- "match_mapping_type" : "date",
70
- "mapping" : { "type" : "date", "doc_values" : true }
71
- }
72
- }, {
73
- "geo_point_fields" : {
74
- "match" : "*",
75
- "match_mapping_type" : "geo_point",
76
- "mapping" : { "type" : "geo_point", "doc_values" : true }
77
- }
78
- } ],
79
- "properties" : {
80
- "@timestamp": { "type": "date", "doc_values" : true },
81
- "@version": { "type": "string", "index": "not_analyzed", "doc_values" : true },
82
- "geoip" : {
83
- "type" : "object",
84
- "dynamic": true,
85
- "properties" : {
86
- "ip": { "type": "ip", "doc_values" : true },
87
- "location" : { "type" : "geo_point", "doc_values" : true },
88
- "latitude" : { "type" : "float", "doc_values" : true },
89
- "longitude" : { "type" : "float", "doc_values" : true }
90
- }
91
- }
92
- }
93
- }
94
- }
95
- }
@@ -1,46 +0,0 @@
1
- {
2
- "template" : "logstash-*",
3
- "version" : 50001,
4
- "settings" : {
5
- "index.refresh_interval" : "5s"
6
- },
7
- "mappings" : {
8
- "_default_" : {
9
- "_all" : {"enabled" : true, "norms" : false},
10
- "dynamic_templates" : [ {
11
- "message_field" : {
12
- "path_match" : "message",
13
- "match_mapping_type" : "string",
14
- "mapping" : {
15
- "type" : "text",
16
- "norms" : false
17
- }
18
- }
19
- }, {
20
- "string_fields" : {
21
- "match" : "*",
22
- "match_mapping_type" : "string",
23
- "mapping" : {
24
- "type" : "text", "norms" : false,
25
- "fields" : {
26
- "keyword" : { "type": "keyword", "ignore_above": 256 }
27
- }
28
- }
29
- }
30
- } ],
31
- "properties" : {
32
- "@timestamp": { "type": "date", "include_in_all": false },
33
- "@version": { "type": "keyword", "include_in_all": false },
34
- "geoip" : {
35
- "dynamic": true,
36
- "properties" : {
37
- "ip": { "type": "ip" },
38
- "location" : { "type" : "geo_point" },
39
- "latitude" : { "type" : "half_float" },
40
- "longitude" : { "type" : "half_float" }
41
- }
42
- }
43
- }
44
- }
45
- }
46
- }
@@ -1,27 +0,0 @@
1
- {
2
- "cluster_name" : "dev",
3
- "nodes" : {
4
- "Ur_68iBvTlm7Xr1HgSsh6w" : {
5
- "name" : "dev-es-master01",
6
- "transport_address" : "http://localhost:9200",
7
- "host" : "127.0.0.1",
8
- "ip" : "127.0.0.1",
9
- "version" : "2.4.6",
10
- "build" : "5376dca"
11
- },
12
- "sari4do3RG-mgh2CIZeHwA" : {
13
- "name" : "dev-es-data01",
14
- "transport_address" : "http://localhost:9201",
15
- "host" : "127.0.0.1",
16
- "ip" : "127.0.0.1",
17
- "version" : "2.4.6",
18
- "build" : "5376dca",
19
- "http_address" : "127.0.0.1:9201",
20
- "http" : {
21
- "bound_address" : [ "[::1]:9201", "127.0.0.1:9201" ],
22
- "publish_address" : "127.0.0.1:9201",
23
- "max_content_length_in_bytes" : 104857600
24
- }
25
- }
26
- }
27
- }
@@ -1,2 +0,0 @@
1
- ctx._source.counter += event["count"]
2
-
@@ -1,2 +0,0 @@
1
- ctx._source.counter += event["data"]["count"]
2
-
@@ -1,2 +0,0 @@
1
- ctx._source.counter = event["counter"]
2
-
@@ -1,150 +0,0 @@
1
- require_relative "../../../spec/es_spec_helper"
2
-
3
- if ESHelper.es_version_satisfies?('>= 2', '< 6')
4
- describe "Update actions using groovy scripts", :integration => true, :update_tests => 'groovy' do
5
- require "logstash/outputs/elasticsearch"
6
-
7
- def get_es_output( options={} )
8
- settings = {
9
- "manage_template" => true,
10
- "index" => "logstash-update",
11
- "template_overwrite" => true,
12
- "hosts" => get_host_port(),
13
- "action" => "update",
14
- "script_lang" => "groovy"
15
- }
16
- LogStash::Outputs::ElasticSearch.new(settings.merge!(options))
17
- end
18
-
19
- before :each do
20
- @es = get_client
21
- # Delete all templates first.
22
- # Clean ES of data before we start.
23
- @es.indices.delete_template(:name => "*")
24
- # This can fail if there are no indexes, ignore failure.
25
- @es.indices.delete(:index => "*") rescue nil
26
- @es.index(
27
- :index => 'logstash-update',
28
- :type => doc_type,
29
- :id => "123",
30
- :body => { :message => 'Test', :counter => 1 }
31
- )
32
- @es.indices.refresh
33
- end
34
-
35
- context "scripted updates" do
36
- it "should increment a counter with event/doc 'count' variable" do
37
- subject = get_es_output({ 'document_id' => "123", 'script' => 'scripted_update', 'script_type' => 'file' })
38
- subject.register
39
- subject.multi_receive([LogStash::Event.new("count" => 2)])
40
- r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "123", :refresh => true)
41
- expect(r["_source"]["counter"]).to eq(3)
42
- end
43
-
44
- it "should increment a counter with event/doc '[data][count]' nested variable" do
45
- subject = get_es_output({ 'document_id' => "123", 'script' => 'scripted_update_nested', 'script_type' => 'file' })
46
- subject.register
47
- subject.multi_receive([LogStash::Event.new("data" => { "count" => 3 })])
48
- r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "123", :refresh => true)
49
- expect(r["_source"]["counter"]).to eq(4)
50
- end
51
-
52
- it "should increment a counter with event/doc 'count' variable with inline script" do
53
- subject = get_es_output({
54
- 'document_id' => "123",
55
- 'script' => 'ctx._source.counter += event["counter"]',
56
- 'script_lang' => 'groovy',
57
- 'script_type' => 'inline'
58
- })
59
- subject.register
60
- subject.multi_receive([LogStash::Event.new("counter" => 3 )])
61
- r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "123", :refresh => true)
62
- expect(r["_source"]["counter"]).to eq(4)
63
- end
64
-
65
- it "should increment a counter with event/doc 'count' variable with event/doc as upsert and inline script" do
66
- subject = get_es_output({
67
- 'document_id' => "123",
68
- 'doc_as_upsert' => true,
69
- 'script' => 'if( ctx._source.containsKey("counter") ){ ctx._source.counter += event["counter"]; } else { ctx._source.counter = event["counter"]; }',
70
- 'script_lang' => 'groovy',
71
- 'script_type' => 'inline'
72
- })
73
- subject.register
74
- subject.multi_receive([LogStash::Event.new("counter" => 3 )])
75
- r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "123", :refresh => true)
76
- expect(r["_source"]["counter"]).to eq(4)
77
- end
78
-
79
- it "should, with new doc, set a counter with event/doc 'count' variable with event/doc as upsert and inline script" do
80
- subject = get_es_output({
81
- 'document_id' => "456",
82
- 'doc_as_upsert' => true,
83
- 'script' => 'if( ctx._source.containsKey("counter") ){ ctx._source.counter += event["count"]; } else { ctx._source.counter = event["count"]; }',
84
- 'script_lang' => 'groovy',
85
- 'script_type' => 'inline'
86
- })
87
- subject.register
88
- subject.multi_receive([LogStash::Event.new("counter" => 3 )])
89
- r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "456", :refresh => true)
90
- expect(r["_source"]["counter"]).to eq(3)
91
- end
92
-
93
- it "should increment a counter with event/doc 'count' variable with indexed script" do
94
- @es.put_script lang: 'groovy', id: 'indexed_update', body: { script: 'ctx._source.counter += event["count"]' }
95
- subject = get_es_output({
96
- 'document_id' => "123",
97
- 'script' => 'indexed_update',
98
- 'script_lang' => 'groovy',
99
- 'script_type' => 'indexed'
100
- })
101
- subject.register
102
- subject.multi_receive([LogStash::Event.new("count" => 4 )])
103
- r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "123", :refresh => true)
104
- expect(r["_source"]["counter"]).to eq(5)
105
- end
106
- end
107
-
108
- context "when update with upsert" do
109
- it "should create new documents with provided upsert" do
110
- subject = get_es_output({ 'document_id' => "456", 'upsert' => '{"message": "upsert message"}' })
111
- subject.register
112
- subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
113
- r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "456", :refresh => true)
114
- expect(r["_source"]["message"]).to eq('upsert message')
115
- end
116
-
117
- it "should create new documents with event/doc as upsert" do
118
- subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true })
119
- subject.register
120
- subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
121
- r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "456", :refresh => true)
122
- expect(r["_source"]["message"]).to eq('sample message here')
123
- end
124
-
125
- it "should fail on documents with event/doc as upsert at external version" do
126
- subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true, 'version' => 999, "version_type" => "external" })
127
- expect { subject.register }.to raise_error(LogStash::ConfigurationError)
128
- end
129
- end
130
-
131
- context "updates with scripted upsert" do
132
- it "should create new documents with upsert content" do
133
- subject = get_es_output({ 'document_id' => "456", 'script' => 'scripted_update', 'upsert' => '{"message": "upsert message"}', 'script_type' => 'file' })
134
- subject.register
135
- subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
136
- r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "456", :refresh => true)
137
- expect(r["_source"]["message"]).to eq('upsert message')
138
- end
139
-
140
- it "should create new documents with event/doc as script params" do
141
- subject = get_es_output({ 'document_id' => "456", 'script' => 'scripted_upsert', 'scripted_upsert' => true, 'script_type' => 'file' })
142
- subject.register
143
- subject.multi_receive([LogStash::Event.new("counter" => 1)])
144
- @es.indices.refresh
145
- r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "456", :refresh => true)
146
- expect(r["_source"]["counter"]).to eq(1)
147
- end
148
- end
149
- end
150
- end