1. Updating Documents(更新文档)

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.4/_updating_documents.html

译文链接 : http://www.apache.wiki/pages/viewpage.action?pageId=4260713

贡献者 : 那伊抹微笑ApacheCNApache中文网

除了可以索引和替换文档之外,我们也可以更新文档。不过,请注意尽管 Elasticsearch 没有在后台马上更新。每当我们做一次更新,Elasticsearch 删除旧的文档,然后一次性应用更新索引一个新文档。

这个例子演示了如何去更新我们先前的文档(ID1),通过修改 name 字段的值为 “Jane Doe” :

curl -XPOST 'localhost:9200/customer/external/1/_update?pretty&pretty' -d'
{
  "doc": { "name": "Jane Doe" }
}'

这个例子演示了如何去更新我们先前的文档(ID1),通过修改 name 字段的值为 “Jane Doe”,并且同时添加 age 字段 :

curl -XPOST 'localhost:9200/customer/external/1/_update?pretty&pretty' -d'
{
  "doc": { "name": "Jane Doe", "age": 20 }
}'

更新也是通过使用简单的简本来执行。这个例子演示了使用简本来将 age5 :

curl -XPOST 'localhost:9200/customer/external/1/_update?pretty&pretty' -d'
{
  "script" : "ctx._source.age += 5"
}'

在上面的例子中,ctx._source 代表当前将被更新的源文档。

请注意,在编写该文档时,在同一时间中更新只能够被执行一个文档上。在将来,Elasticsearch 也许会提供给定一个查询条件(像 SQL UPDATE-WHERE 语句)来更新多个文档的功能。

Copyright © Kilvn 2021. all right reserved,powered by Gitbook最后更新时间: 2021-06-08 20:22:42

results matching ""

    No results matching ""