Hi Thanks for your reply.
Here is my complete conf file
input {
file {
sincedb_path => "..../sincedb_path.txt"
path => "..../logstash-5.5.2/bin/test1.json"
type => "test"
start_position => "beginning"
}
}
filter {
json {
source => "message"
target => "docs"
}
ruby {
code => "
h = event.get('docs')
def arrays_to_hash(h)
h.each do |k,v|
# If v is nil, an array is being iterated and the value is k.
# If v is not nil, a hash is being iterated and the value is v.
value = v || k
if value.is_a?(Array)
value_hash = {}
value.each_with_index do |v, i|
value_hash[i.to_s] = v
end
h[k] = value_hash
end
if value.is_a?(Hash) || value.is_a?(Array)
arrays_to_hash(value)
end
end
end
test= arrays_to_hash(h);
event.set('itemnum',test);
"
}
}
output {
stdout { codec => rubydebug}
elasticsearch {
action => "index"
.......
}
}
This is my Elastic output stdout { codec => rubydebug }
{
"itemnum" => {
"cars" => {
"0" => {
"models" => {
"0" => "Fiesta",
"1" => "Focus",
"2" => "Mustang"
},
"name" => "Ford"
},
"1" => {
"models" => {
"0" => "320",
"1" => "X3",
"2" => "X5"
},
"name" => "BMW"
},
"2" => {
"models" => {
"0" => "500",
"1" => "Panda"
},
"name" => "Fiat"
}
},
"name" => "John",
"age" => 30
},
"@timestamp" => 2017-09-22T10:11:49.757Z,
"docs" => {
"cars" => [
[0] {
"models" => [
[0] "Fiesta",
[1] "Focus",
[2] "Mustang"
],
"name" => "Ford"
},
[1] {
"models" => [
[0] "320",
[1] "X3",
[2] "X5"
],
"name" => "BMW"
},
[2] {
"models" => [
[0] "500",
[1] "Panda"
],
"name" => "Fiat"
}
],
"name" => "John",
"age" => 30
},
How can get three records
itemnum.cars.name : Ford
itemnum.cars.name : BMW
itemnum.cars.name : Fiat
and these field should be repeated, so that i can see Kibana dicover
itemnum.name : John
itemnum.age : 30
currently i am getting like this
itemnum.name : John
itemnum.age : 30
itemnum.cars.0.name : Ford
itemnum.cars.1.name : BMW
itemnum.cars.2.name : Fiat