生成 Elasticsearch POST /_bulk 批量上传json例子
时间: 2023-12-25 08:53:49 浏览: 25
以下是一个简单的 Elasticsearch POST /_bulk 批量上传 JSON 的例子:
```
POST /_bulk
{ "index" : { "_index" : "myindex", "_type" : "mytype", "_id" : "1" } }
{ "title" : "The quick brown fox", "body" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit." }
{ "index" : { "_index" : "myindex", "_type" : "mytype", "_id" : "2" } }
{ "title" : "The lazy dog", "body" : "Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." }
```
以上代码将上传两个文档到名为 `myindex`,类型为 `mytype` 的索引中。 第一个文档的 ID 是 `1`,标题是 `The quick brown fox`,正文是 `Lorem ipsum dolor sit amet, consectetur adipiscing elit.`。第二个文档的 ID 是 `2`,标题是 `The lazy dog`,正文是 `Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.`。请注意,每个文档都需要用一个单独的 JSON 对象表示,这些对象之间用换行符分隔。`index` 字段指定了每个文档的索引名称、类型和 ID。