2

I am having a following set of information in my logs. It is in JSON format.

{   
  "someField":"someValue",   
  "columns":"[colName1, colName2, colName3, ... colNameN]", 
  "someField":"someValue" 
}

I want this to be stored as an array in a same field columns.

The usecase I want to show up is how many users have used the particular column called colName1 and the count of it.

I am using ELK stak 5.x

3 Answers 3

2

if your source is directly json format

use the json plugin

filter {
  json {
    source => "message"
  }
}

The array field will auto convert to array

https://www.elastic.co/guide/en/logstash/current/plugins-filters-json.html

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

9 Comments

I understand that it it will be auto convert to array. but in my case I am using ThreadContext to put the value. and ThreadContext only supports String vales. so although my values looks in an array format, they are actually exported in string format in a log file. So will that affact in this case?
ThreadContext is the logstash plugin ? if not the json format that you provide should come from message field by default, so i don't know you means ThreadContext
No its not logstash plugin but it is a library in java that helps me to put values in a field and use it across.
@VishalKinjavdekar i think your data will still come through the message ,could you check ?
I checked... In kibana it shows as a text field even after using json plugin
|
2

I got the solution by referring both the above answers. This is what I did.

To remove [ and ] from the string I used this:

mutate {
        gsub => ["columns", "[\[\]]", ""]
    }

and then to convert it into array:

    mutate {
        split => { "columns" => "," }
    }

Comments

1

Mutate in output.conf might help you.

Follow this link - https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-replace

Although direct conversion from string to array is not supported. I faced same use case some time back, used merge functionality for that. I would suggest have some dummy field and merge with 'columns' field to create new array field. Hope this helps.

Comments

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.