0
votes

I have this JSON

{
"users":"[{"id":1,"name":"bob"},{"id":2,"name":"alice"},{"id":3,"name":"david"}]",
"date":"23/01/2017"
}

even if I'm using the logstash filter:

filter {
    split {
        field => "users"
    }
}

the message is stored in elastic as single event

users => [{"id":1,"name":"bob"},{"id":2,"name":"alice"},{"id":3,"name":"david"}] date=> 23/01/2017

question1: how I can convert the user field from string to a json array to have this

"users":[{"id":1,"name":"bob"},{"id":2,"name":"alice"},{"id":1,"name":"david"}],
"date":"23/01/2017"

question 2: how I can store this nested json as a multiple json events in elastic

Expected output:

{
"id":1,
"name":"bob",
"date":"23/01/2017"
}

{
"id":2,
"name":"alice",
"date":"23/01/2017"
}

{
"id":3,
"name":"david",
"date":"23/01/2017"
}

Thanks in advance for your answer

1

1 Answers

1
votes

For Question 1 you can use Logstash JSON filter plugin for converting JSON format.

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

For Question 2, I think from one line you can not make multiple documents, you need to put logs new line for a new document.

Logstath can parse one log line or multiple loglines to prepare one elasticsearch document. But from one line it can't create multiple documents.