{
"events": [
{
"Message": "Get all motors",
"Level": "Information"
},
{
"Message": "Get all motors",
"Level": "Information"
}
]
}
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [
{
"_source" : {
"@timestamp" : "2019-03-28T10:05:05.649Z",
"@version" : "1",
"Message" : "Get all motors",
"Level" : "Information"
}
},
{
"_source" : {
"@timestamp" : "2019-03-28T10:05:05.649Z",
"@version" : "1",
"Message" : "Get all motors",
"Level" : "Information"
}
}
]
}
我使用了以下logstash配置:
# Http input listening port 8080
input {
http {
#default host 0.0.0.0:8080
codec => json
}
}
# Separate the logs
filter {
split {
field => "events"
target => "e"
}
mutate {
remove_field => ["events", "headers"]
}
}
# Send the logs to Elasticsearch
output {
elasticsearch {
hosts => "localhost:9200"
index=>"mylog-%{+YYYY.MM.dd}"
document_type => "log"
}
}
实际搜索结果:
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [
{
"_source" : {
"@timestamp" : "2019-03-28T10:05:05.649Z",
"@version" : "1",
"e" : {
"Message" : "Get all motors",
"Level" : "Information"
}
}
},
{
"_source" : {
"@timestamp" : "2019-03-28T10:05:05.649Z",
"@version" : "1",
"e" : {
"Message" : "Get all motors",
"Level" : "Information"
}
}
}
]
}
不同的是:
-
在实际结果中,我的日志信息嵌套在
e
财产
-
_source
)
Elasticsearch文档建议删除
target
从
filter
filter {
split {
field => "events"
}
}
但如果我这样做,我的结果将是空的:
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [
{
"_source" : {
"@timestamp" : "2019-03-28T10:05:05.649Z",
"@version" : "1"
}
},
{
"_source" : {
"@timestamp" : "2019-03-28T10:05:05.649Z",
"@version" : "1"
}
}
]
}
我怎样才能达到预期的效果?
我的环境:
-
Windows 10 x64专业版
-
麋鹿6.7
-
JDK 8u201型