提炼:

  1. Elasticsearch 中的 document 是不可更改的。
  2. 更新整个 document 使用 PUT /website/blog/123
  3. 更新 document 的步骤是:①把旧的文档标记为已删除②索引新的文档③在之后执行别的索引操作时,后台自动删除旧的文档

    原文:

    Documents in Elasticsearch are immutable;we cannot change them. Instead, if we need to update an existing document, we reindex or replace it, which we can do using the same index API that we have already discussed in Indexing a Document.

    PUT /website/blog/123 { “title”:”My first blog entry”, “text”: “I am starting to get the hang of this…”, “date”: “2014/01/02” }

In the response, we can see that Elasticsearch has incremented the _version number:

{ “_index” : “website”, “_type” : “blog”, “_id” : “123”, “_version” : 2, “created”: false }

The created flag is set to false because a document with the same index, type, and ID already existed.
Internally, Elasticsearch has marked the document as deleted and added an entirely new document. The old version of the document doesn’t disappear immediately, although you won’t be able to access it. Elasticsearch cleans up deleted documents in the background as you continue to index more data.
Later in this chapter, we introduce the update API, which can be used to make partial updates to a document.

This API appears to change documents in place, but actually Elasticsearch is following exactly the same process as described previously:

1.Retrieve the JSON from the old document 2.Change it 3.Delete the old document 4.Index a new document

The only difference is that the update API achieves this through a single client request, instead of requring separate get and index requests.

单词解释:
immutable: Something that is immutable will never change or cannot be changed.
internal : Internal is used to describe things that exist or happen inside a country or organization.