ES:document的全量替换、强制创建以及图解lazy delete机制
1、document的全量替换
(1)语法与创建文档是一样的,如果document id不存在,那么就是创建;如果document id已经存在,那么就是全量替换操作,替换document的json串内容
PUT /test_index/test_type/4
{
"test_fied":"test test1111111"
}
(2)document是不可变的,如果要修改document的内容,第一种方式就是全量替换,直接对document重新建立索引,替换里面所有的内容
(3)es会将老的document标记为deleted,然后新增我们给定的一个document,当我们创建越来越多的document的时候,es会在适当的时机在后台自动删除标记为deleted的document
2、document的强制创建
(1)创建文档与全量替换的语法是一样的,有时我们只是想新建文档,不想替换文档,如果强制进行创建呢?
PUT /test_index/test_type/4/_create
{
"test_fied":"test "
}
{
"error": {
"root_cause": [
{
"type": "version_conflict_engine_exception",
"reason": "[test_type][4]: version conflict, document already exists (current version [4])",
"index_uuid": "oT8hUqMcTXOB5Fx-rfWlzw",
"shard": "2",
"index": "test_index"
}
],
"type": "version_conflict_engine_exception",
"reason": "[test_type][4]: version conflict, document already exists (current version [4])",
"index_uuid": "oT8hUqMcTXOB5Fx-rfWlzw",
"shard": "2",
"index": "test_index"
},
"status": 409
}
3、document的删除
DELETE /test_index/test_type/4
(2)不会直接物理删除,只会将其标记为deleted,当数据越来越多的时候,在后台自动删除