opensearch-project / logstash-output-opensearch

A Logstash plugin that sends event data to a OpenSearch clusters and stores as an index.
https://opensearch.org/docs/latest/clients/logstash/index/
Apache License 2.0
104 stars 80 forks source link

Can this plugin provide script function? #214

Open alwaysliving opened 1 year ago

alwaysliving commented 1 year ago

Is your feature request related to a problem? Please describe. I would like to request for the plugin to provide a way to use scripts, similar to what is offered in the output-elasticsearch plugin. Documentation for output-elasticsearch can be found here: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-script

Describe the solution you'd like Currently, I have no problems using scripts with Elasticsearch. However, I have intentions of using OpenSearch instead and there are several places in my existing output-elasticsearch Logstash configuration where scripts are used. When I tried to use the same method with output-opensearch, an error message was returned and the program did not run.

Describe alternatives you've considered None at the moment.

Additional context I have included some sample code below.

        elasticsearch {
            hosts => ["my_host"]
            index => "my_index"
            document_id => "doc_id"
            action => "update"
            doc_as_upsert=>true
            manage_template => false

            script_lang => "painless"
            script_type => "inline"
            script => '
                if (ctx._source.total_duration == null) {
                    ctx._source.total_duration = params.event.get("total_duration");
                    ctx._source.last_logout = params.event.get("last_logout");
                }
                if (ctx._source.last_logout != params.event.get("last_logout")) {
                    ctx._source.total_duration_s = ctx._source.total_duration + params.event.get("total_duration");
                    ctx._source.last_logout = params.event.get("last_logout");
                }
            '
        }