import json file data into elastic search using logstash
我想将 json 文件数据导入弹性搜索。
这是我的logstash配置文件--
input { file {
type =>"json"
path =>"C:\\Users\\Desktop\
ewJSON.json"
start_position =>"beginning" sincedb_path =>"\\dev\
ull"
} }output {
stdout {
codec => rubydebug
}
elasticsearch {
hosts => "localhost:9200"
index =>"jsondata1"
} }
这是我的json文件---
{
"fruit":"Apple",
"size":"small",
"color":"Red"
},
{
"fruit":"Papaya",
"size":"Large",
"color":"Yellow"
"test" :"sweet"
}
我使用这个命令执行了上面的配置文件----
1 | logstash -f logstashcon.conf |
但我在弹性搜索索引中得到如下数据--
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | { "took": 2, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 10, "max_score": 1, "hits": [ { "_index":"jsondata1", "_type":"json", "_id":"AWNniXbgMkzPgBTTablA", "_score": 1, "_source": { "path":"C:\\\\Users\\\\Desktop\\\ ewJSON.json", "@timestamp":"2018-05-16T06:00:48.302Z", "@version":"1", "host":"user-102", "message":"{\ ", "type":"json" } }, { "_index":"jsondata1", "_type":"json", "_id":"AWNniXbgMkzPgBTTablB", "_score": 1, "_source": { "path":"C:\\\\Users\\\\Desktop\\\ ewJSON.json", "@timestamp":"2018-05-16T06:00:48.694Z", "@version":"1", "host":"user-102", "message":" "fruit": "Apple",\ ", "type":"json" } }, { "_index":"jsondata1", "_type":"json", "_id":"AWNniXbgMkzPgBTTablE", "_score": 1, "_source": { "path":"C:\\\\Users\\\\Desktop\\\ ewJSON.json", "@timestamp":"2018-05-16T06:00:48.696Z", "@version":"1", "host":"user-102", "message":"},\ ", "type":"json" } }, { "_index":"jsondata1", "_type":"json", "_id":"AWNniXbgMkzPgBTTablC", "_score": 1, "_source": { "path":"C:\\\\Users\\\\Desktop\\\ ewJSON.json", "@timestamp":"2018-05-16T06:00:48.695Z", "@version":"1", "host":"user-102", "message":" "size": "Large",\ ", "type":"json" } }, { "_index":"jsondata1", "_type":"json", "_id":"AWNniXbgMkzPgBTTablD", "_score": 1, "_source": { "path":"C:\\\\Users\\\\Desktop\\\ ewJSON.json", "@timestamp":"2018-05-16T06:00:48.696Z", "@version":"1", "host":"user-102", "message":" "color": "Red"\ ", "type":"json" } }, { "_index":"jsondata1", "_type":"json", "_id":"AWNniXbgMkzPgBTTablG", "_score": 1, "_source": { "path":"C:\\\\Users\\\\Desktop\\\ ewJSON.json", "@timestamp":"2018-05-16T06:00:48.698Z", "@version":"1", "host":"user-102", "message":""fruit": "Papaya",\ ", "type":"json" } }, { "_index":"jsondata1", "_type":"json", "_id":"AWNniXbgMkzPgBTTablJ", "_score": 1, "_source": { "path":"C:\\\\Users\\\\Desktop\\\ ewJSON.json", "@timestamp":"2018-05-16T06:00:48.699Z", "@version":"1", "host":"user-102", "message":"}\ ", "type":"json" } }, { "_index":"jsondata1", "_type":"json", "_id":"AWNniXbgMkzPgBTTablH", "_score": 1, "_source": { "path":"C:\\\\Users\\\\Desktop\\\ ewJSON.json", "@timestamp":"2018-05-16T06:00:48.699Z", "@version":"1", "host":"user-102", "message":" "size": "Large",\ ", "type":"json" } }, { "_index":"jsondata1", "_type":"json", "_id":"AWNniXbgMkzPgBTTablF", "_score": 1, "_source": { "path":"C:\\\\Users\\\\Desktop\\\ ewJSON.json", "@timestamp":"2018-05-16T06:00:48.698Z", "@version":"1", "host":"user-102", "message":"{\ ", "type":"json" } }, { "_index":"jsondata1", "_type":"json", "_id":"AWNniXbgMkzPgBTTablI", "_score": 1, "_source": { "path":"C:\\\\Users\\\\Desktop\\\ ewJSON.json", "@timestamp":"2018-05-16T06:00:48.699Z", "@version":"1", "host":"user-102", "message":" "color": "Yellow"\ ", "type":"json" } } ] } } |
请帮助我获得正确的输出
谢谢!
你需要使用 JSON 过滤器插件来构建你的输出,
例如,如果您在
1 2 3 4 5 | filter { json { source =>"message" } } |
这就是文档所说的,
It takes an existing field which contains JSON and expands it into an
actual data structure within the Logstash event.
请在此处阅读有关用法和示例的更多信息。