Skip to content

Commit 57f95a2

Browse files
authored
fix stored painless script integration testing for es 6 and above (logstash-plugins#688)
1 parent 2212fed commit 57f95a2

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

docs/index.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ Set script name for scripted update mode
477477
* Value type is <<string,string>>
478478
* Default value is `"painless"`
479479

480-
Set the language of the used script. If not set, this defaults to painless in ES 5.0
480+
Set the language of the used script. If not set, this defaults to painless in ES 5.0.
481+
When using indexed (stored) scripts on Elasticsearch 6 and higher, you must set this parameter to `""` (empty string).
481482

482483
[id="plugins-{type}s-{plugin}-script_type"]
483484
===== `script_type`

spec/integration/outputs/painless_update_spec.rb

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,29 @@ def get_es_output( options={} )
9393
insist { r["_source"]["counter"] } == 3
9494
end
9595

96-
if ESHelper.es_version_satisfies?('<6')
97-
context 'with an indexed script' do
98-
it "should increment a counter with event/doc 'count' variable with indexed script" do
99-
@es.put_script lang: 'painless', id: 'indexed_update', body: { script: 'ctx._source.counter += params.event.count' }
100-
subject = get_es_output({
101-
'document_id' => "123",
102-
'script' => 'indexed_update',
103-
'script_type' => 'indexed'
104-
})
105-
subject.register
106-
subject.multi_receive([LogStash::Event.new("count" => 4 )])
107-
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
108-
insist { r["_source"]["counter"] } == 5
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' => '')
109112
end
113+
114+
subject = get_es_output(plugin_parameters)
115+
subject.register
116+
subject.multi_receive([LogStash::Event.new("count" => 4 )])
117+
r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
118+
insist { r["_source"]["counter"] } == 5
110119
end
111120
end
112121
end

0 commit comments

Comments
 (0)