【发布时间】:2016-10-26 23:04:42
【问题描述】:
我正在尝试根据 ES 版本 2.3.4 的搜索查询更新几个文档。我的用例是搜索两个字段与特定值匹配的文档,然后添加具有特定值的新字段。因此,假设我想搜索名字为“John”和姓氏为“Smith”的所有员工,并在他们的个人资料中添加一个新字段“job”,其中包含值“Engineer”。 所以我的第一个问题是是否可以使用 update_by_query API 的“doc”选项来执行此操作(与更新 API 相同)。
如果不是,并且必须使用脚本(这是我现在这样做的方式),那么也许有人可以帮助我摆脱以下错误:
{"error":{"root_cause":[{"type":"class_cast_exception","reason":"java.lang.String cannot be cast to java.util.Map"}],"type":"class_cast_exception","reason":"java.lang.String cannot be cast to java.util.Map"},"status":500}
我使用的代码如下:
curl -XPOST -s 'http://localhost:9200/test_index/_update_by_query?conflicts=proceed' -d'
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"match": { "first_name" : "John" }
},
{
"match": { "last_name" : "Smith" }
}
]
}
}
}
},
"script" : "ctx._source.job = \"Engineer\""
}'
当使用 count API 发送相同的查询(没有“脚本”字段)时,不会报告错误,并且会重新调整正确数量的文档。
【问题讨论】:
标签: elasticsearch