我们可以在不指定Elasticsearch的文档ID的情况下执行批量索引吗?

时间:2013-03-14 08:19:47

标签: elasticsearch

是否可以在不指定文档ID的情况下执行批量索引?我希望Elasticsearch在索引时为我生成一个随机ID,但可以这样做吗?

2 个答案:

答案 0 :(得分:19)

是的,你可以!

测试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}}]}

答案 1 :(得分: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
      }
    }
  ]
}

`