ElasticSearch JSON 文件导入(批量 API)

ElasticSearch JSON file import (Bulk API)

我在 Whosebug 上看到了一些与此类似的 posts,但我仍然不清楚如何将包含 JSON 个文档的大文件索引到 ElasticSearch 中;我收到如下错误:

{"error":"ActionRequestValidationException[Validation Failed: 1: index is missing;2: type is missing;]","status":400}

{"took":231,"errors":false,"items":[{"index":{"_index":"test","_type":"type1","_id":"1","_version":7,"status":200}}]

我有一个 JSON 文件,大小约为 2Gb,这是我实际要导入的文件。但首先,为了了解 Bulk API 的工作原理,我创建了一个只有一行实际数据的小文件:

testfile.json

{"index":{"_id":"someId"}} \n
{"id":"testing"}\n

我在 SO 上从另一个 post 那里得到了这个。我理解第一行是一个header,我也理解第一行的"index"是要发送给ES的命令;但是,这仍然不起作用。有人可以给我一个工作示例并清楚地解释如何将 JSON 文件导入 ES 吗?

谢谢!

以下示例来自 elasticsearch 文档: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html?q=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" : "index1"} }
{ "doc" : {"field2" : "value2"} }

所以第一行告诉elastic将第二行的文档索引到index test中,type1 with _id 1。它将用field1索引文档。如果它们都转到相同的索引和类型,您可以更改 url。检查 link 样本。

在第三行你看到一个删除操作的例子,这个文档不需要第四行的文档。

小心处理非常大的文档,2 Gb 可能太大了。它需要先发送到 elastic,elastic 将其加载到内存中。所以要发送的记录数量是有限制的。