Elasticsearch专题精讲—— REST APIs —— Document APIs —— Update By Query API

发布时间 2023-06-06 15:53:12作者: 左扬

REST APIs —— Document APIs ——  Update By Query API

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-update-by-query.html#docs-update-by-query

Updates documents that match the specified query. If no query is specified, performs an update on every document in the data stream or index without modifying the source, which is useful for picking up mapping changes.

更新 API(_update) 允许根据提供的脚本更新文件。该操作从索引中获取文档,运行脚本(使用可选的脚本语言和参数),并对结果进行索引(还允许删除或忽略该操作)。它使用版本控制来确保在 Get 和 Reindex 操作期间没有发生任何更新。

        POST /< target>/_update_by_query

        POST/< target>/_update_by_query 

1、Request(请求)

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-update-by-query.html#docs-update-by-query-api-request

        POST /< index>/_update/<_id>

    POST /< index>/_update/<_id>

2、Prerequisites(先决条件)

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-update-by-query.html#docs-update-by-query-api-prereqs

If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or alias:

如果启用了 Elasticsearch 安全特性,您必须对目标数据流、索引或别名拥有以下索引特权:

3、Description(描述)

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-update.html#update-api-desc

Enables you to script document updates. The script can update, delete, or skip modifying the document. The update API also supports passing a partial document, which is merged into the existing document. To fully replace an existing document, use the index API.

使能够编写文档更新脚本。脚本可以更新、删除或跳过对文档的修改。更新 API 还支持传递部分文档,该部分文档合并到现有文档中。若要完全替换现有文档,请使用索引 API。

This operation: