是否可以在不指定文档 ID 的情况下进行批量索引?我希望 Elasticsearch 在索引时为我生成一个随机 ID,但可以这样做吗?
问问题
12348 次
2 回答
22
是的你可以!
在 0.90.0.Beta1 上测试:
$ cat requests
{ "index" : { "_index" : "test", "_type" : "type1" } }
{ "field1" : "value1" }
$ curl -s -XPOST localhost:9200/_bulk --data-binary @requests; echo
{"took":6,"items":[{"create":{"_index":"test","_type":"type1","_id":"IWqsRqyhRVq-F69OLIngTA","_version":1,"ok":true}}]}
于 2013-03-14T09:05:37.450 回答
3
这是另一个不指定 _id 的批量上传示例。
`
curl -XPOST "http://localhost:9200/_bulk" -d'
{ "index" : { "_index" : "test", "_type" : "demo" } }
{ "title" : "Quick brown rabbits", "content" : "Brown rabbits are commonly seen" }
{ "index" : { "_index" : "test", "_type" : "demo" } }
{ "title" : "Keeping pets healthy", "content" : "My quick brown fox eats rabbits
`
回复如下
`
{
"took": 451,
"errors": false,
"items": [
{
"create": {
"_index": "test",
"_type": "demo",
"_id": "AVYDtp_fxosF2Bdj7ghV",
"_version": 1,
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"status": 201
}
},
{
"create": {
"_index": "test",
"_type": "demo",
"_id": "AVYDtp_fxosF2Bdj7ghW",
"_version": 1,
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"status": 201
}
}
]
}
`
于 2016-07-19T15:24:23.320 回答