要执行批量更新操作,您可以使用Elasticsearch的_update_by_query
API。这个API允许您对匹配特定查询的文档执行批量更新。以下是一个基本的示例,说明如何使用这个API来更新您提供的ID列表中的文档的_status
字段。
首先,您需要确保您的Elasticsearch集群已经安装并运行。然后,您可以使用以下命令来执行批量更新:
在这个例子中,_update_by_query
API将会查找所有ID在提供的列表中的文档,并将它们的_status
字段更新为4。
es 批量更新
POST _update_by_query { "script": { "source": "ctx._source._status = params.new_status", "lang": "painless", "params": { "new_status": 4 } }, "query": { "terms": { "_id": [ "103228397094660841991", "103342372156642594567", "103468611696669718025", // ... 更多的ID "10767164087407048828946" ] } } }
POST demand/_update_by_query
{
"script": {
"source": "ctx._source.xxx_status = 11",
"lang": "painless"
},
"query": {
"terms": {
"_id": [
"118990940285692034057",
"16212771556710360666117",
"118854456972820467721"
]
}
}
}
----------------------------------
GET demand/_search
{
"query": {
"terms": {
"id": [
"10322843397d340940841991",
"103343423721542594567",
"10343486116966934718025",
// ... 更多的ID值
"11438855693472820467721"
]
}
},
"_source": ["xxx_status"],
"size": 100 // 指定返回的文档数量为100
}
TRANSLATE with x English TRANSLATE with COPY THE URL BELOW Back EMBED THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget: Bing Webmaster Portal Back 标签:status,update,更新,source,API,query,数据,es From: https://www.cnblogs.com/gaoyuechen/p/18128955