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
     
     
     
  • 相关阅读:
    layui的模块化和非模块化使用
    layui实现类似于bootstrap的模态框功能
    ajax下载文件
    【IDEA】IDEA中maven项目pom.xml依赖不生效解决
    主-主数据库系统架构
    MyEclipse x.x各版本终极优化配置指南
    Cactus入门
    有史以来最出彩的编程语言名字
    安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果
    第一次讲课总结
  • 原文地址:https://www.cnblogs.com/shuaiandjun/p/10272265.html
Copyright © 2011-2022 走看看