1

EDIT -> I created a plugin for this, available here:

You can install with bin/logstash-plugin install logstash-filter-collect I have a logstash entry like:

 "cvals" => [
            [0] {
                   "text" => "cval something 1",
                "indices" => [
                    [0] 17,
                    [1] 29
                ]
            },
            [1] {
                   "text" => "cval something else 2",
                "indices" => [
                    [0] 17,
                    [1] 29
                ]
            }
            ...
            [n] {
                "text" => "cval more stuff n",
                "indices" => [
                    [0] 17,
                    [1] 29
                ]
            }

        ]

I would like to mutate it to be:

"cvals_terms" => [ "cval something 1", "cval something else 2", ..., "cval more stuff n"]

How do I do this with Logstash? I could do it with a block of Ruby code, but there has to be a way to do it with mutate or something I think...

1 Answer 1

0

Using logstash-oss v6.3.0, the following should work:

filter {
  ruby {
    code => "event.set('cvals_terms', event.get('cvals').map{ |n| n['text'] })"
  }
}

The downside is that you're coding in strings, which will hurt maintainability on the long run.

Sign up to request clarification or add additional context in comments.

3 Comments

See the plugins in my original post, no need for custom code now.
This one-liner is provided as an alternative approach for people who seek a lightweight solution. Great job on the plugin though!
For moving Ruby code outside of Logstash pipeline, see also: elastic.co/blog/moving-ruby-code-out-of-logstash-pipeline

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.