[英]How to import zipped json into elasticsearch using logstash?
[英]How I can feed to ElasticSearch with Logstash or curl?
我正在嘗試將所有json導入我的elasticsearch中。 我已經為此目的嘗試了curl
命令,但是沒有用,因為它開始給出解析錯誤。
這是我嘗試的:
curl -XPOST "http://localhost:9200/test" -d "@test.json"
curl -XPOST "http://localhost:9200/test/_bulk" -d "@test.json"
curl -XPOST "http://localhost:9200/test/_bulk" --data-binary "@test.json"
curl -s -XPOST "http://localhost:9200/test/_bulk" --data-binary "@test.json"
和許多其他嘗試。 但是我得到的是Parsing error
。 因此想知道向我的所有記錄提供彈性搜索的方法是什么?
另外,如果有人可以用logstash幫助我解決問題,那將是很大的幫助。 請讓我知道最好的建議。
這是JSON中的示例數據,可能用換行符分隔。 樣本數據
這是錯誤:
{
"error" : {
"root_cause" : [
{
"type" : "parse_exception",
"reason" : "Failed to derive xcontent"
}
],
"type" : "parse_exception",
"reason" : "Failed to derive xcontent"
},
"status" : 400
}
您需要像這樣更改json:
{ "index" : { "_index" : "test", "_type" : "type" } }
{"data":...}
{ "index" : { "_index" : "test", "_type" : "type" } }
{"data":...}
{ "index" : { "_index" : "test", "_type" : "type" } }
{"data":...}
然后,您可以運行:
curl -s -H "Content-Type: application/x-ndjson" -XPOST localhost:9200/_bulk --data-binary "@test.json"
閱讀有關Bulk API的更多信息。
如果您希望使用Logstash做到這一點,則可以將stdin輸入與json過濾器一起使用 ,然后將elasticsearch輸出使用 。 類似於(未經測試)的內容:
input {
stdin { }
}
filter {
json {
source => "message"
}
mutate {
remove_field => [ "message" ]
}
}
output {
elasticsearch {
}
}
然后啟動:
cat test.json | bin/logstash -f logstash.conf
我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.