Elasticsearch "put-if-absent" 创建行为似乎不起作用

Elasticsearch "put-if-absent" behavior on create doesn't seem to work

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html,它说

Automatic ID Generation

The index operation can be executed without specifying the id. 
In such a case, an id will be generated automatically. 
In addition, the op_type will automatically be set to create. 
Here is an example (note the POST used instead of PUT):

$ curl -XPOST 'http://localhost:9200/twitter/tweet/' -d '{
    "user" : "kimchy",
    "post_date" : "2009-11-15T14:12:12",
    "message" : "trying out Elasticsearch"
}'

所以根据我的阅读,如果我 运行 查询两次,它应该只索引一个文档,第二个应该 return 409。但是当我实际上 运行它(在 elasticsearch 1.3.2 上),它每次都会创建一个文档!这是怎么回事,如何在不指定文档 ID 的情况下仅在文档不存在的情况下将其编入索引?

你不能,如果你不指定一个 id,将生成一个新的 guid。 create op_type 意味着它知道它不需要进行更新,因为它有一个新的唯一 ID。

您可以对数据进行校验和并将其设置为 id,但如果数据每次都发生变化,那将是一个坏主意。