当我在ElasticSearch中插入2个具有相同id的文档时会发生什么?



我想知道当我在同一索引中添加具有现有id的文档时会发生什么。

我知道它不会重复,我不知道的是Elasticsearch是否会忽略后者或是否会更新第一个。

非常感谢。

最新的文档将简单地覆盖具有相同ID的前一个文档,并且版本计数将增加1。

很容易测试:

# 1. create the document
PUT test/_doc/1
{
"test": "me"
}
# 2. response from the creation
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,               <---- check this
"result" : "created",         <---- check this
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
# 3. update the document
PUT test/_doc/1
{
"test": "me2"
}
# 4. response from the update
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_version" : 2,               <---- check this
"result" : "updated",         <---- check this
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}

最新更新