Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
| <<plugins-{type}s-{plugin}-routing>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-script>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-script_lang>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-script_type>> |<<string,string>>, one of `["inline", "indexed", "file"]`|No
| <<plugins-{type}s-{plugin}-script_type>> |<<string,string>>, one of `["inline", "indexed", "file", "source"]`|No
| <<plugins-{type}s-{plugin}-script_var_name>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-scripted_upsert>> |<<boolean,boolean>>|No
| <<plugins-{type}s-{plugin}-sniffing>> |<<boolean,boolean>>|No
Expand Down Expand Up @@ -679,11 +679,12 @@ When using indexed (stored) scripts on Elasticsearch 6 and higher, you must set
[id="plugins-{type}s-{plugin}-script_type"]
===== `script_type`

* Value can be any of: `inline`, `indexed`, `file`
* Value can be any of: `inline`, `source`, `indexed`, `file`
* Default value is `["inline"]`

Define the type of script referenced by "script" variable
inline : "script" contains inline script
inline : "script" contains inline script (ES 5.x)
source : "script" contains inline script (ES +6.0)
indexed : "script" contains the name of script directly indexed in elasticsearch
file : "script" contains the name of script stored in elasticsearch's config directory

Expand Down
1 change: 1 addition & 0 deletions lib/logstash/outputs/elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require "thread" # for safe queueing
require "uri" # for escaping user input
require "forwardable"
require 'logstash/plugin_mixins/deprecation_logger_support'

# .Compatibility Note
# [NOTE]
Expand Down
5 changes: 3 additions & 2 deletions lib/logstash/outputs/elasticsearch/common_configs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ def self.included(mod)
mod.config :script, :validate => :string, :default => ""

# Define the type of script referenced by "script" variable
# inline : "script" contains inline script
# inline : "script" contains inline script (ES 5.x)
# source : "script" contains inline script (ES +6.0)
# indexed : "script" contains the name of script directly indexed in elasticsearch
# file : "script" contains the name of script stored in elasticseach's config directory
mod.config :script_type, :validate => ["inline", 'indexed', "file"], :default => ["inline"]
mod.config :script_type, :validate => ["inline", 'indexed', "file", "source"], :default => ["inline"]

# Set the language of the used script. If not set, this defaults to painless in ES 5.0
mod.config :script_lang, :validate => :string, :default => "painless"
Expand Down
2 changes: 2 additions & 0 deletions lib/logstash/outputs/elasticsearch/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ def update_action_builder(args, source)
source['script']['file'] = args.delete(:_script)
when 'inline'
source['script']['inline'] = args.delete(:_script)
when 'source'
source['script']['source'] = args.delete(:_script)
end
source['script']['lang'] = @options[:script_lang] if @options[:script_lang] != ''
else
Expand Down
7 changes: 7 additions & 0 deletions lib/logstash/outputs/elasticsearch/http_client_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

module LogStash; module Outputs; class ElasticSearch;
module HttpClientBuilder
include LogStash::Util::Loggable
include LogStash::PluginMixins::DeprecationLoggerSupport

def self.build(logger, hosts, params)
client_settings = {
:pool_max => params["pool_max"],
Expand Down Expand Up @@ -76,6 +79,10 @@ def self.build(logger, hosts, params)
"doc_as_upsert and scripted_upsert are mutually exclusive."
) if params["doc_as_upsert"] and params["scripted_upsert"]

if params['action'] == 'update' && params['script_type'] == 'inline'
deprecation_logger.deprecated("The 'inline' value for script type is deprecated and won't be supported in Elasticsearch 8.0. Please use 'source' instead.")
end

raise(
LogStash::ConfigurationError,
"Specifying action => 'update' needs a document_id."
Expand Down
1 change: 1 addition & 0 deletions logstash-output-elasticsearch.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'stud', ['>= 0.0.17', '~> 0.0']
s.add_runtime_dependency 'cabin', ['~> 0.6']
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
s.add_runtime_dependency 'logstash-mixin-deprecation_logger_support', '~>1.0'

s.add_development_dependency 'logstash-codec-plain'
s.add_development_dependency 'logstash-devutils'
Expand Down
12 changes: 12 additions & 0 deletions spec/integration/outputs/painless_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ def get_es_output( options={} )
expect(r["_source"]["counter"]).to eq(4)
end

it "should increment a counter with event/doc 'count' variable with source script" do
subject = get_es_output({
'document_id' => "123",
'script' => 'ctx._source.counter += params.event.counter',
'script_type' => 'source'
})
subject.register
subject.multi_receive([LogStash::Event.new("counter" => 3 )])
r = @es.get(:index => 'logstash-update', :type => doc_type, :id => "123", :refresh => true)
expect(r["_source"]["counter"]).to eq(4)
end

it "should increment a counter with event/doc 'count' variable with event/doc as upsert and inline script" do
subject = get_es_output({
'document_id' => "123",
Expand Down