小编典典

如何通过一个API调用将多个文档发送到Elastic

elasticsearch

我是Elastic的新手,我需要一种方法,只需调用一个即可将多个文档推送到Elastic POST http://localhost:9200/myindex/mytype/

主体架构如下所示:

{ 
"docs": [ 
{ "_source": {"message":"message1"} }, 
{ "_source": {"message":"message2"} } 
] 
}

我尝试了摄取API和管道,但没有运气。

可能吗?


阅读 277

收藏
2020-06-22

共1个答案

小编典典

谢谢@JinLee和@NishantSaini的帮助。我想记录一下我所做的。

首先,添加/_bulk端点。因此,API调用现在为:POST http://localhost:9200/myindex/mytype/_bulk

现在将Content-Type标题设置为application/x-ndjson

然后身体必须是这样的:

{"index":{}}
{"message":"message1"}
{"index":{}}
{"message":"message2"}

现在一切正常!

2020-06-22