0

我正在使用弹性搜索客户端。

var elasticsearch = require('elasticsearch');
   var client = new elasticsearch.Client({
   host:"https://********",
   log: 'trace',
});

我有 JSON 对象可以说

[{"name":"abc", "age": 23},{"name":"bcd", "age": 25}......]

我的目标是批量插入。我试过但没有工作。

client.bulk({
    index: "person",
    type: '_doc',
    body: [{JSON}] // input as JSON format

})
4

1 回答 1

0

关于批量 API,需要记住的主要内容是:

使用换行分隔 JSON (NDJSON) 结构在请求正文中指定操作。

因此,遵循请求正文格式、新行、操作和元数据非常重要。

例子:

POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }

文档

于 2020-04-16T14:24:39.593 回答