0

以下是弹性搜索文档提供的批量插入示例:https ://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html

POST _bulk
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }

他们提到“因为这种格式使用文字 \n 作为分隔符,请确保 JSON 操作和源没有很好地打印出来”。

我想知道这种输入格式背后的原因以及他们为什么不选择 JSON 对象数组。

例如:

POST _bulk
    [{{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
    { "field1" : "value1" }},
    { "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
    { "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
    { "field1" : "value3" }
    { "update" : {"_id" : "1", "_type" : "type1", "_index" : "test"} }
    { "doc" : {"field2" : "value2"} }]

上面的结构不正确,但类似的东西在 REST API 开发标准中我是否缺少一些常见的东西?分隔符而不是数组?

4

1 回答 1

1

这允许 Bulk 端点逐行处理正文。如果它是一个 JSON 数组,ES 必须将整个 JSON 主体加载并解析到内存中,以便一个接一个地提取数组元素。

知道块体可能非常大(即数百 MB),这是一个优化,以防止您的 ES 服务器在发送大量请求时崩溃。

于 2017-09-11T15:52:02.223 回答