zoukankan      html  css  js  c++  java
  • (十一)Updating Documents

    In addition to being able to index and replace documents, we can also update documents. Note though that Elasticsearch does not actually do in-place updates under the hood. Whenever we do an update, Elasticsearch deletes the old document and then indexes a new document with the update applied to it in one shot.

    除了能够索引和替换文档,我们还可以更新文档。请注意,Elasticsearch实际上并没有在内部进行就地更新。每当我们进行更新时,Elasticsearch都会删除旧文档,然后一次性对应用了更新的新文档编制索引。
     
     This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe":
    此示例显示如何通过将名称字段更改为“Jane Doe”来更新以前的文档(ID为1):
    curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'
    {
      "doc": { "name": "Jane Doe" }
    }
    '

    This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe" and at the same time add an age field to it:

    此示例显示如何通过将名称字段更改为“Jane Doe”来更新我们以前的文档(ID为1),同时向其添加年龄字段:
     
    curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'
    {
      "doc": { "name": "Jane Doe", "age": 20 }
    }
    '

    Updates can also be performed by using simple scripts. This example uses a script to increment the age by 5:

    也可以使用简单脚本执行更新。此示例使用脚本将年龄增加5:
     
    curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'
    {
      "script" : "ctx._source.doc.age += 5"
    }
    '

    In the above example, ctx._source refers to the current source document that is about to be updated.

    在上面的示例中,ctx._source指的是即将更新的当前源文档。
     
    Elasticsearch provides the ability to update multiple documents given a query condition (like an SQL UPDATE-WHERE statement). See docs-update-by-query API
    Elasticsearch提供了在给定查询条件(如SQL UPDATE-WHERE语句)的情况下更新多个文档的功能。请参阅docs-update-by-query API
     
     
     
  • 相关阅读:
    ubuntu 16.04 tmux
    ubuntu 16.04 samba 文件共享
    ubuntu 16.04 有道词典
    ubuntu bless 16字节每行
    Win7任务栏图标大小调整为等宽
    ubuntu 16.04 vnc server
    ubuntu 16.04 U盘多媒体不自动弹出
    Linux录屏软件
    通过apt-get安装nvidia驱动
    调试X Server
  • 原文地址:https://www.cnblogs.com/shuaiandjun/p/10272265.html
Copyright © 2011-2022 走看看