logstash-output-elasticsearch 7.4.3-java → 8.0.0-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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +5 -18
- data/docs/index.asciidoc +13 -50
- data/lib/logstash/outputs/elasticsearch/common.rb +39 -43
- data/lib/logstash/outputs/elasticsearch/common_configs.rb +2 -11
- data/lib/logstash/outputs/elasticsearch/http_client.rb +22 -27
- data/lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb +2 -2
- data/lib/logstash/outputs/elasticsearch/http_client/pool.rb +12 -31
- data/lib/logstash/outputs/elasticsearch/template_manager.rb +6 -4
- data/logstash-output-elasticsearch.gemspec +1 -1
- data/spec/es_spec_helper.rb +0 -6
- data/spec/integration/outputs/compressed_indexing_spec.rb +44 -46
- data/spec/integration/outputs/delete_spec.rb +49 -51
- data/spec/integration/outputs/groovy_update_spec.rb +129 -131
- data/spec/integration/outputs/index_version_spec.rb +81 -82
- data/spec/integration/outputs/ingest_pipeline_spec.rb +49 -51
- data/spec/integration/outputs/painless_update_spec.rb +130 -170
- data/spec/integration/outputs/parent_spec.rb +55 -149
- data/spec/integration/outputs/sniffer_spec.rb +2 -5
- data/spec/integration/outputs/templates_5x_spec.rb +82 -81
- data/spec/integration/outputs/templates_spec.rb +81 -81
- data/spec/integration/outputs/update_spec.rb +99 -101
- data/spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb +5 -30
- data/spec/unit/outputs/elasticsearch/http_client/pool_spec.rb +0 -3
- data/spec/unit/outputs/elasticsearch/http_client_spec.rb +12 -11
- data/spec/unit/outputs/elasticsearch/template_manager_spec.rb +25 -13
- data/spec/unit/outputs/elasticsearch_spec.rb +1 -10
- metadata +4 -6
@@ -1,101 +1,100 @@
|
|
1
1
|
require_relative "../../../spec/es_spec_helper"
|
2
2
|
require "logstash/outputs/elasticsearch"
|
3
3
|
|
4
|
-
if ESHelper.es_version_satisfies?(">= 2")
|
5
|
-
describe "Versioned indexing", :integration => true do
|
6
|
-
require "logstash/outputs/elasticsearch"
|
7
4
|
|
8
|
-
|
5
|
+
describe "Versioned indexing", :integration => true, :version_greater_than_equal_to_2x => true do
|
6
|
+
require "logstash/outputs/elasticsearch"
|
9
7
|
|
10
|
-
|
11
|
-
# Delete all templates first.
|
12
|
-
# Clean ES of data before we start.
|
13
|
-
es.indices.delete_template(:name => "*")
|
14
|
-
# This can fail if there are no indexes, ignore failure.
|
15
|
-
es.indices.delete(:index => "*") rescue nil
|
16
|
-
es.indices.refresh
|
17
|
-
end
|
8
|
+
let(:es) { get_client }
|
18
9
|
|
19
|
-
|
20
|
-
|
10
|
+
before :each do
|
11
|
+
# Delete all templates first.
|
12
|
+
# Clean ES of data before we start.
|
13
|
+
es.indices.delete_template(:name => "*")
|
14
|
+
# This can fail if there are no indexes, ignore failure.
|
15
|
+
es.indices.delete(:index => "*") rescue nil
|
16
|
+
es.indices.refresh
|
17
|
+
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
19
|
+
context "when index only" do
|
20
|
+
subject { LogStash::Outputs::ElasticSearch.new(settings) }
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
"manage_template" => true,
|
30
|
-
"index" => "logstash-index",
|
31
|
-
"template_overwrite" => true,
|
32
|
-
"hosts" => get_host_port(),
|
33
|
-
"action" => "index",
|
34
|
-
"script_lang" => "groovy",
|
35
|
-
"document_id" => "%{my_id}"
|
36
|
-
}
|
37
|
-
end
|
22
|
+
before do
|
23
|
+
subject.register
|
24
|
+
end
|
38
25
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
26
|
+
describe "unversioned output" do
|
27
|
+
let(:settings) do
|
28
|
+
{
|
29
|
+
"manage_template" => true,
|
30
|
+
"index" => "logstash-index",
|
31
|
+
"template_overwrite" => true,
|
32
|
+
"hosts" => get_host_port(),
|
33
|
+
"action" => "index",
|
34
|
+
"script_lang" => "groovy",
|
35
|
+
"document_id" => "%{my_id}"
|
36
|
+
}
|
49
37
|
end
|
50
38
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
"version_type" => "external",
|
63
|
-
}
|
64
|
-
end
|
39
|
+
it "should default to ES version" do
|
40
|
+
subject.multi_receive([LogStash::Event.new("my_id" => "123", "message" => "foo")])
|
41
|
+
r = es.get(:index => 'logstash-index', :type => 'logs', :id => "123", :refresh => true)
|
42
|
+
expect(r["_version"]).to eq(1)
|
43
|
+
expect(r["_source"]["message"]).to eq('foo')
|
44
|
+
subject.multi_receive([LogStash::Event.new("my_id" => "123", "message" => "foobar")])
|
45
|
+
r2 = es.get(:index => 'logstash-index', :type => 'logs', :id => "123", :refresh => true)
|
46
|
+
expect(r2["_version"]).to eq(2)
|
47
|
+
expect(r2["_source"]["message"]).to eq('foobar')
|
48
|
+
end
|
49
|
+
end
|
65
50
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
51
|
+
describe "versioned output" do
|
52
|
+
let(:settings) do
|
53
|
+
{
|
54
|
+
"manage_template" => true,
|
55
|
+
"index" => "logstash-index",
|
56
|
+
"template_overwrite" => true,
|
57
|
+
"hosts" => get_host_port(),
|
58
|
+
"action" => "index",
|
59
|
+
"script_lang" => "groovy",
|
60
|
+
"document_id" => "%{my_id}",
|
61
|
+
"version" => "%{my_version}",
|
62
|
+
"version_type" => "external",
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should respect the external version" do
|
67
|
+
id = "ev1"
|
68
|
+
subject.multi_receive([LogStash::Event.new("my_id" => id, "my_version" => "99", "message" => "foo")])
|
69
|
+
r = es.get(:index => 'logstash-index', :type => 'logs', :id => id, :refresh => true)
|
70
|
+
expect(r["_version"]).to eq(99)
|
71
|
+
expect(r["_source"]["message"]).to eq('foo')
|
72
|
+
end
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
it "should ignore non-monotonic external version updates" do
|
75
|
+
id = "ev2"
|
76
|
+
subject.multi_receive([LogStash::Event.new("my_id" => id, "my_version" => "99", "message" => "foo")])
|
77
|
+
r = es.get(:index => 'logstash-index', :type => 'logs', :id => id, :refresh => true)
|
78
|
+
expect(r["_version"]).to eq(99)
|
79
|
+
expect(r["_source"]["message"]).to eq('foo')
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
subject.multi_receive([LogStash::Event.new("my_id" => id, "my_version" => "98", "message" => "foo")])
|
82
|
+
r2 = es.get(:index => 'logstash-index', :type => 'logs', :id => id, :refresh => true)
|
83
|
+
expect(r2["_version"]).to eq(99)
|
84
|
+
expect(r2["_source"]["message"]).to eq('foo')
|
85
|
+
end
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
it "should commit monotonic external version updates" do
|
88
|
+
id = "ev3"
|
89
|
+
subject.multi_receive([LogStash::Event.new("my_id" => id, "my_version" => "99", "message" => "foo")])
|
90
|
+
r = es.get(:index => 'logstash-index', :type => 'logs', :id => id, :refresh => true)
|
91
|
+
expect(r["_version"]).to eq(99)
|
92
|
+
expect(r["_source"]["message"]).to eq('foo')
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
94
|
+
subject.multi_receive([LogStash::Event.new("my_id" => id, "my_version" => "100", "message" => "foo")])
|
95
|
+
r2 = es.get(:index => 'logstash-index', :type => 'logs', :id => id, :refresh => true)
|
96
|
+
expect(r2["_version"]).to eq(100)
|
97
|
+
expect(r2["_source"]["message"]).to eq('foo')
|
99
98
|
end
|
100
99
|
end
|
101
100
|
end
|
@@ -1,19 +1,18 @@
|
|
1
1
|
require_relative "../../../spec/es_spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
3
|
+
describe "Ingest pipeline execution behavior", :integration => true, :version_greater_than_equal_to_5x => true do
|
4
|
+
subject! do
|
5
|
+
require "logstash/outputs/elasticsearch"
|
6
|
+
settings = {
|
7
|
+
"hosts" => "#{get_host_port()}",
|
8
|
+
"pipeline" => "apache-logs"
|
9
|
+
}
|
10
|
+
next LogStash::Outputs::ElasticSearch.new(settings)
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
let(:ftw_client) { FTW::Agent.new }
|
14
|
+
let(:ingest_url) { "http://#{get_host_port()}/_ingest/pipeline/apache-logs" }
|
15
|
+
let(:apache_logs_pipeline) { '
|
17
16
|
{
|
18
17
|
"description" : "Pipeline to parse Apache logs",
|
19
18
|
"processors" : [
|
@@ -25,53 +24,52 @@ if ESHelper.es_version_satisfies?(">= 5")
|
|
25
24
|
}
|
26
25
|
]
|
27
26
|
}'
|
28
|
-
|
27
|
+
}
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
before :each do
|
30
|
+
# Delete all templates first.
|
31
|
+
require "elasticsearch"
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
# Clean ES of data before we start.
|
34
|
+
@es = get_client
|
35
|
+
@es.indices.delete_template(:name => "*")
|
37
36
|
|
38
|
-
|
39
|
-
|
37
|
+
# This can fail if there are no indexes, ignore failure.
|
38
|
+
@es.indices.delete(:index => "*") rescue nil
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
# delete existing ingest pipeline
|
41
|
+
req = ftw_client.delete(ingest_url)
|
42
|
+
ftw_client.execute(req)
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
# register pipeline
|
45
|
+
req = ftw_client.put(ingest_url, :body => apache_logs_pipeline)
|
46
|
+
req.headers["Content-Type"] = "application/json"
|
47
|
+
ftw_client.execute(req)
|
49
48
|
|
50
|
-
|
51
|
-
|
49
|
+
#TODO: Use esclient
|
50
|
+
#@es.ingest.put_pipeline :id => 'apache_pipeline', :body => pipeline_defintion
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
subject.register
|
53
|
+
subject.multi_receive([LogStash::Event.new("message" => '183.60.215.50 - - [01/Jun/2015:18:00:00 +0000] "GET /scripts/netcat-webserver HTTP/1.1" 200 182 "-" "Mozilla/5.0 (compatible; EasouSpider; +http://www.easou.com/search/spider.html)"')])
|
54
|
+
@es.indices.refresh
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
56
|
+
#Wait or fail until everything's indexed.
|
57
|
+
Stud::try(20.times) do
|
58
|
+
r = @es.search
|
59
|
+
insist { r["hits"]["total"] } == 1
|
62
60
|
end
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
63
|
+
it "indexes using the proper pipeline" do
|
64
|
+
results = @es.search(:index => 'logstash-*', :q => "message:\"netcat\"")
|
65
|
+
insist { results["hits"]["total"] } == 1
|
66
|
+
insist { results["hits"]["hits"][0]["_source"]["response"] } == "200"
|
67
|
+
insist { results["hits"]["hits"][0]["_source"]["bytes"] } == "182"
|
68
|
+
insist { results["hits"]["hits"][0]["_source"]["verb"] } == "GET"
|
69
|
+
insist { results["hits"]["hits"][0]["_source"]["request"] } == "/scripts/netcat-webserver"
|
70
|
+
insist { results["hits"]["hits"][0]["_source"]["auth"] } == "-"
|
71
|
+
insist { results["hits"]["hits"][0]["_source"]["ident"] } == "-"
|
72
|
+
insist { results["hits"]["hits"][0]["_source"]["clientip"] } == "183.60.215.50"
|
73
|
+
insist { results["hits"]["hits"][0]["_source"]["junkfieldaaaa"] } == nil
|
76
74
|
end
|
77
75
|
end
|
@@ -1,188 +1,148 @@
|
|
1
1
|
require_relative "../../../spec/es_spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
describe "Update actions using painless scripts", :integration => true, :update_tests => 'painless', :version_greater_than_equal_to_5x => true do
|
4
|
+
require "logstash/outputs/elasticsearch"
|
5
|
+
|
6
|
+
def get_es_output( options={} )
|
7
|
+
settings = {
|
8
|
+
"manage_template" => true,
|
9
|
+
"index" => "logstash-update",
|
10
|
+
"template_overwrite" => true,
|
11
|
+
"hosts" => get_host_port(),
|
12
|
+
"action" => "update",
|
13
|
+
"script_lang" => "painless"
|
14
|
+
}
|
15
|
+
LogStash::Outputs::ElasticSearch.new(settings.merge!(options))
|
16
|
+
end
|
6
17
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
before :each do
|
19
|
+
@es = get_client
|
20
|
+
# Delete all templates first.
|
21
|
+
# Clean ES of data before we start.
|
22
|
+
@es.indices.delete_template(:name => "*")
|
23
|
+
# This can fail if there are no indexes, ignore failure.
|
24
|
+
@es.indices.delete(:index => "*") rescue nil
|
25
|
+
@es.index(
|
26
|
+
:index => 'logstash-update',
|
27
|
+
:type => 'logs',
|
28
|
+
:id => "123",
|
29
|
+
:body => { :message => 'Test', :counter => 1 }
|
30
|
+
)
|
31
|
+
@es.indices.refresh
|
32
|
+
end
|
20
33
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@es.index(
|
29
|
-
:index => 'logstash-update',
|
30
|
-
:type => 'logs',
|
31
|
-
:id => "123",
|
32
|
-
:body => { :message => 'Test', :counter => 1 }
|
33
|
-
)
|
34
|
-
@es.indices.refresh
|
34
|
+
context "scripted updates" do
|
35
|
+
it "should increment a counter with event/doc 'count' variable" do
|
36
|
+
subject = get_es_output({ 'document_id' => "123", 'script' => 'scripted_update', 'script_type' => 'file' })
|
37
|
+
subject.register
|
38
|
+
subject.multi_receive([LogStash::Event.new("count" => 2)])
|
39
|
+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
40
|
+
insist { r["_source"]["counter"] } == 3
|
35
41
|
end
|
36
42
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
45
|
-
insist { r["_source"]["counter"] } == 3
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should increment a counter with event/doc '[data][count]' nested variable" do
|
49
|
-
subject = get_es_output({ 'document_id' => "123", 'script' => 'scripted_update_nested', 'script_type' => 'file' })
|
50
|
-
subject.register
|
51
|
-
subject.multi_receive([LogStash::Event.new("data" => { "count" => 3 })])
|
52
|
-
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
53
|
-
insist { r["_source"]["counter"] } == 4
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should increment a counter with event/doc 'count' variable with inline script" do
|
59
|
-
subject = get_es_output({
|
60
|
-
'document_id' => "123",
|
61
|
-
'script' => 'ctx._source.counter += params.event.counter',
|
62
|
-
'script_type' => 'inline'
|
63
|
-
})
|
64
|
-
subject.register
|
65
|
-
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
66
|
-
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
67
|
-
insist { r["_source"]["counter"] } == 4
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should increment a counter with event/doc 'count' variable with event/doc as upsert and inline script" do
|
71
|
-
subject = get_es_output({
|
72
|
-
'document_id' => "123",
|
73
|
-
'doc_as_upsert' => true,
|
74
|
-
'script' => 'if( ctx._source.containsKey("counter") ){ ctx._source.counter += params.event.counter; } else { ctx._source.counter = params.event.counter; }',
|
75
|
-
'script_type' => 'inline'
|
76
|
-
})
|
77
|
-
subject.register
|
78
|
-
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
79
|
-
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
80
|
-
insist { r["_source"]["counter"] } == 4
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should, with new doc, set a counter with event/doc 'count' variable with event/doc as upsert and inline script" do
|
84
|
-
subject = get_es_output({
|
85
|
-
'document_id' => "456",
|
86
|
-
'doc_as_upsert' => true,
|
87
|
-
'script' => 'if( ctx._source.containsKey("counter") ){ ctx._source.counter += params.event.counter; } else { ctx._source.counter = params.event.counter; }',
|
88
|
-
'script_type' => 'inline'
|
89
|
-
})
|
90
|
-
subject.register
|
91
|
-
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
92
|
-
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
93
|
-
insist { r["_source"]["counter"] } == 3
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'with an indexed script' do
|
97
|
-
it "should increment a counter with event/doc 'count' variable with indexed script" do
|
98
|
-
if ESHelper.es_version_satisfies?('<6')
|
99
|
-
@es.perform_request(:put, "_scripts/painless/indexed_update", {}, {"script" => "ctx._source.counter += params.event.count" })
|
100
|
-
else
|
101
|
-
@es.perform_request(:put, "_scripts/indexed_update", {}, {"script" => {"source" => "ctx._source.counter += params.event.count", "lang" => "painless"}})
|
102
|
-
end
|
103
|
-
|
104
|
-
plugin_parameters = {
|
105
|
-
'document_id' => "123",
|
106
|
-
'script' => 'indexed_update',
|
107
|
-
'script_type' => 'indexed'
|
108
|
-
}
|
109
|
-
|
110
|
-
if ESHelper.es_version_satisfies?('>= 6.0.0')
|
111
|
-
plugin_parameters.merge!('script_lang' => '')
|
112
|
-
end
|
43
|
+
it "should increment a counter with event/doc '[data][count]' nested variable" do
|
44
|
+
subject = get_es_output({ 'document_id' => "123", 'script' => 'scripted_update_nested', 'script_type' => 'file' })
|
45
|
+
subject.register
|
46
|
+
subject.multi_receive([LogStash::Event.new("data" => { "count" => 3 })])
|
47
|
+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
48
|
+
insist { r["_source"]["counter"] } == 4
|
49
|
+
end
|
113
50
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
51
|
+
it "should increment a counter with event/doc 'count' variable with inline script" do
|
52
|
+
subject = get_es_output({
|
53
|
+
'document_id' => "123",
|
54
|
+
'script' => 'ctx._source.counter += params.event.counter',
|
55
|
+
'script_lang' => 'painless',
|
56
|
+
'script_type' => 'inline'
|
57
|
+
})
|
58
|
+
subject.register
|
59
|
+
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
60
|
+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
61
|
+
insist { r["_source"]["counter"] } == 4
|
62
|
+
end
|
122
63
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
64
|
+
it "should increment a counter with event/doc 'count' variable with event/doc as upsert and inline script" do
|
65
|
+
subject = get_es_output({
|
66
|
+
'document_id' => "123",
|
67
|
+
'doc_as_upsert' => true,
|
68
|
+
'script' => 'if( ctx._source.containsKey("counter") ){ ctx._source.counter += params.event.counter; } else { ctx._source.counter = params.event.counter; }',
|
69
|
+
'script_lang' => 'painless',
|
70
|
+
'script_type' => 'inline'
|
71
|
+
})
|
72
|
+
subject.register
|
73
|
+
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
74
|
+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
75
|
+
insist { r["_source"]["counter"] } == 4
|
76
|
+
end
|
131
77
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
78
|
+
it "should, with new doc, set a counter with event/doc 'count' variable with event/doc as upsert and inline script" do
|
79
|
+
subject = get_es_output({
|
80
|
+
'document_id' => "456",
|
81
|
+
'doc_as_upsert' => true,
|
82
|
+
'script' => 'if( ctx._source.containsKey("counter") ){ ctx._source.counter += params.event.counter; } else { ctx._source.counter = params.event.counter; }',
|
83
|
+
'script_lang' => 'painless',
|
84
|
+
'script_type' => 'inline'
|
85
|
+
})
|
86
|
+
subject.register
|
87
|
+
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
|
88
|
+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
89
|
+
insist { r["_source"]["counter"] } == 3
|
90
|
+
end
|
139
91
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
92
|
+
it "should increment a counter with event/doc 'count' variable with indexed script" do
|
93
|
+
@es.put_script lang: 'painless', id: 'indexed_update', body: { script: 'ctx._source.counter += params.event.count' }
|
94
|
+
subject = get_es_output({
|
95
|
+
'document_id' => "123",
|
96
|
+
'script' => 'indexed_update',
|
97
|
+
'script_lang' => 'painless',
|
98
|
+
'script_type' => 'indexed'
|
99
|
+
})
|
100
|
+
subject.register
|
101
|
+
subject.multi_receive([LogStash::Event.new("count" => 4 )])
|
102
|
+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
|
103
|
+
insist { r["_source"]["counter"] } == 5
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "when update with upsert" do
|
108
|
+
it "should create new documents with provided upsert" do
|
109
|
+
subject = get_es_output({ 'document_id' => "456", 'upsert' => '{"message": "upsert message"}' })
|
110
|
+
subject.register
|
111
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
112
|
+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
113
|
+
insist { r["_source"]["message"] } == 'upsert message'
|
144
114
|
end
|
145
115
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
154
|
-
insist { r["_source"]["message"] } == 'upsert message'
|
155
|
-
end
|
116
|
+
it "should create new documents with event/doc as upsert" do
|
117
|
+
subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true })
|
118
|
+
subject.register
|
119
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
120
|
+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
121
|
+
insist { r["_source"]["message"] } == 'sample message here'
|
122
|
+
end
|
156
123
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
163
|
-
insist { r["_source"]["counter"] } == 1
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
124
|
+
it "should fail on documents with event/doc as upsert at external version" do
|
125
|
+
subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true, 'version' => 999, "version_type" => "external" })
|
126
|
+
expect { subject.register }.to raise_error(LogStash::ConfigurationError)
|
127
|
+
end
|
128
|
+
end
|
167
129
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
130
|
+
context "updates with scripted upsert" do
|
131
|
+
it "should create new documents with upsert content" do
|
132
|
+
subject = get_es_output({ 'document_id' => "456", 'script' => 'scripted_update', 'upsert' => '{"message": "upsert message"}', 'script_type' => 'file' })
|
133
|
+
subject.register
|
134
|
+
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
135
|
+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
136
|
+
insist { r["_source"]["message"] } == 'upsert message'
|
137
|
+
end
|
176
138
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
end
|
185
|
-
end
|
139
|
+
it "should create new documents with event/doc as script params" do
|
140
|
+
subject = get_es_output({ 'document_id' => "456", 'script' => 'scripted_upsert', 'scripted_upsert' => true, 'script_type' => 'file' })
|
141
|
+
subject.register
|
142
|
+
subject.multi_receive([LogStash::Event.new("counter" => 1)])
|
143
|
+
@es.indices.refresh
|
144
|
+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
|
145
|
+
insist { r["_source"]["counter"] } == 1
|
186
146
|
end
|
187
147
|
end
|
188
148
|
end
|