如何通过一个API调用将多个文档发送到Elastic [英] How can I send multiple documents to elastic with one API call
问题描述
我是Elastic的新手,我需要一种方法,仅通过调用 POST http://localhost:9200/myindex/mytype/
即可将多个文档推送到Elastic.
I'm new to Elastic and I need a way to push multiple documents to Elastic by only making one call to POST http://localhost:9200/myindex/mytype/
.
主体模式如下:
{
"docs": [
{ "_source": {"message":"message1"} },
{ "_source": {"message":"message2"} }
]
}
我尝试了摄取API和管道,但是没有运气.
I tried with the ingest API and Pipelines with no luck.
有可能吗?
推荐答案
谢谢@JinLee和@NishantSaini都对我的帮助.我想记录一下我的所作所为.
Thanks, both of you @JinLee and @NishantSaini for helping me. I want to document what I did.
首先,添加/_ bulk
端点.因此,API调用现在为: POST http://localhost:9200/myindex/mytype/_bulk
.
First, add /_bulk
endpoint. So the API call is now: POST http://localhost:9200/myindex/mytype/_bulk
.
现在将 Content-Type
标头设置为 application/x-ndjson
然后身体必须是这样的:
Then the body must be like this:
{"index":{}}
{"message":"message1"}
{"index":{}}
{"message":"message2"}
现在一切正常!
这篇关于如何通过一个API调用将多个文档发送到Elastic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!