Json 如何使用Logstash或curl向ElasticSearch提供数据?
我正在尝试将所有json导入elasticsearch。为此,我尝试了Json 如何使用Logstash或curl向ElasticSearch提供数据?,json,curl,
elasticsearch,logstash,Json,Curl,
elasticsearch,Logstash,我正在尝试将所有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
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"
还有许多其他的尝试。但我得到的是解析错误
。因此,我想知道向elasticsearch提供我所有记录的方法是什么?此外,如果有人能帮我解决它与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"
阅读更多关于
如果您希望使用Logstash实现这一点,可以使用a和a,然后使用。类似(未经测试):
然后启动:
cat test.json | bin/logstash -f logstash.conf
我希望这有帮助。您需要像这样更改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"
阅读更多关于
如果您希望使用Logstash实现这一点,可以使用a和a,然后使用。类似(未经测试):
然后启动:
cat test.json | bin/logstash -f logstash.conf
我希望这会有所帮助。BTW如果您将文件拆分为多个文件,如每个文件一个JSON文档,则可以使用project。Let-us.BTW如果您将文件拆分为多个文件,如每个文件一个JSON文档,则可以使用project.Let-us。