Files
elasticsearch/docs/05.数据更新与修改.md
2022-12-02 14:26:43 +08:00

27 lines
998 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 前言
在 Elasticsearch 中文档是**不可改变**的,不能修改它们。如果想要更新现有的文档,需要重建索引或者进行替换,我们可以使用相同的 index API 进行实现。
```
PUT /website/blog/123
{
"title": "My first blog entry",
"text": "I am starting to get the hang of this...",
"date": "2014/01/02"
}
```
在内部Elasticsearch已将旧文档标记为已删除并增加一个全新的文档。 尽管你不能再对旧版本的文档进行访问,但它并不会立即消失。
当继续索引更多的数据Elasticsearch会在后台清理这些已删除文档。
它似乎对文档直接进行了修改但实际上Elasticsearch按前述完全相同方式执行以下过程
- 从旧文档构建JSON
- 更改该JSON
- 删除旧文档
- 索引一个新文档
唯一的区别在于, update API 仅仅通过一个客户端请求来实现这些步骤,而不需要单独的 get 和 index 请求。