I have a log file with json format, and there are json arrays in it. for example, a piece of array log is like below. I am using json+ruby fitler to make the array element parsed flatten. but my filter looks like doesn't work, can the expert please take a look ?
1. array
body { "Action": "TalentSearch", "name": "Shanghai", "ratingCriteria": [{ "id": "sysOverallPotential", "type": "7", "name": "Potential - 3x3 Rating", "item": "null", "scaleId": "Potential", "scaleMin": "1", "scaleMax": "3", "criterias": [{ "id": "tsv2RatingValidFrom", "type": "date", "value": ["2018 - 12 - 04", "2018 - 12 - 31"] }, { "id": "tsv2RatingValidTo", "type": "date", "value": ["2018 - 12 - 31", "2018 - 12 - 31"] }, { "id": "tsv2RatingFromValue", "type": "prepopulate", "value": ["1.0"] }, { "id": "tsv2RatingEndValue", "type": "prepopulate", "value": ["2.0"] }] }] }
2. my json+ruby filter(because field name is dynamic, so use ruby to iterate them)
input { file{ path => "C:/elkstack/elasticsearch-6.5.1/logs/app.log" start_position => "beginning" sincedb_path => "null" codec => "json" } }
filter {
ruby {
code => "event.to_hash.each {|k,v|if v.is_a?(Array)
v.each do |element|if element.is_a?(Hash)
element.each {|k,v| event.set(k, v.split(','))}
else
event.set(k,v)
end
end
else
event.set(k,v)
end}"
}
}
4. actual parsed result
{
"id": "sysOverallPotential",
"item": "null",
"scaleId": "Potential",
"type": "7",
"scaleMax": "3",
"criterias": [
{
"id": "tsv2RatingValidFrom",
"type": "date",
"value": [
"2018 - 12 - 04",
"2018 - 12 - 31"
]
},
{
"id": "tsv2RatingValidTo",
"type": "date",
"value": [
"2018 - 12 - 31",
"2018 - 12 - 31"
]
},
{
"id": "tsv2RatingFromValue",
"type": "prepopulate",
"value": [
"1.0"
]
},
{
"id": "tsv2RatingEndValue",
"type": "prepopulate",
"value": [
"2.0"
]
}
],
"name": "Potential - 3x3 Rating",
"scaleMin": "1"
}
5. my expected parsed result displayed in kibana is flat enough
"body.ratingCriteria.id": "sysOverallPotential" "body.ratingCriteria.type": "7" ... "body.ratingCriteria.criterias.id": "tsv2RatingValidFrom" "body.ratingCriteria.criterias.type": "date" ...