POST /your_index/_update_by_query{ "query": { "bool": { "must": [ { "match": { "contentType": "application/zip" } }, { "exists": { "field": "content" } } ] } }, "script": { "source": "ctx._source.content = ''" }}为什么全部文档都更新了
时间: 2023-07-02 19:08:01 浏览: 51
这个请求会对索引中匹配查询条件的所有文档执行更新操作。如果你想只更新单个文档,可以在查询条件中添加唯一标识符(如文档ID),以确保只有一个文档被更新。例如:
```
POST /your_index/_update_by_query
{
"query": {
"bool": {
"must": [
{ "match": { "contentType": "application/zip" } },
{ "exists": { "field": "content" } }
],
"filter": {
"term": { "_id": "your_document_id" }
}
}
},
"script": {
"source": "ctx._source.content = ''"
}
}
```
这样,只有ID为 "your_document_id" 的文档会被更新。
相关问题
es _update_by_query must_not
`_update_by_query` 是 Elasticsearch 中的一个 API,可以用来根据查询条件更新文档。`must_not` 是 Elasticsearch 中的一个查询关键字,表示查询结果中不包含某个条件。`must_not` 可以用在查询语句中,也可以用在 `_update_by_query` API 中的查询条件中,用来排除某些文档进行更新。例如,可以使用如下语句来更新所有 `status` 字段为 `published` 的文档,但排除所有 `category` 字段为 `test` 的文档:
```
POST my_index/_update_by_query
{
"query": {
"bool": {
"must": [
{
"term": {
"status": "published"
}
}
],
"must_not": [
{
"term": {
"category": "test"
}
}
]
}
},
"script": {
"source": "ctx._source.status = 'archived'"
}
}
```
该请求将会把所有符合查询条件的文档中的 `status` 字段更新为 `archived`。
error: unknown type name 'bool' bool re_bool; /* value of bool */
出现 `unknown type name 'bool'` 的错误提示意味着编译器无法找到 `bool` 类型的定义。
在 C 语言中,`bool` 类型是 C99 标准引入的布尔类型,用于表示真(true)或假(false)。然而,在一些旧的 C 编译器中,并不支持 `bool` 类型。
要解决此问题,您可以尝试以下两种方法之一:
1. 使用 `int` 类型代替 `bool` 类型:在较旧的 C 编译器中,可以使用 `int` 类型来模拟布尔类型。通常,0 表示假(false),非零值表示真(true)。
```c
int re_bool; // value of bool
```
2. 包含 `<stdbool.h>` 头文件:在支持 C99 标准的编译器中,可以包含 `<stdbool.h>` 头文件来定义 `bool` 类型。
```c
#include <stdbool.h>
bool re_bool; // value of bool
```
请根据您的编译器和需求选择适合的方法。希望这可以帮助您解决问题。如果还有其他疑问,请随时提问。