gpt4 book ai didi

elasticsearch - 删除具有特定属性值的所有文档?

转载 作者:行者123 更新时间:2023-12-03 01:27:39 26 4
gpt4 key购买 nike

我正在尝试删除某个属性具有特定值的所有文档。下面的代码是我最好的尝试,但是 ES API 返回了一个解析错误:

const userProperty = "couchDbOrigin";

client.deleteByQuery({
index: "_all",
body: { query: { bool: { must: [{ terms: { [userProperty]: user } }] } } }
});

这段代码有什么问题?

最佳答案

terms query期望标准为数组:

所以你应该使用:

client.deleteByQuery({
index: "_all",
body: { query: { bool: { must: [{ terms: { [userProperty]: [user] } }] } } }
});

但是如果你一次删除一个用户的文档,你应该使用 term query期望一个值并且可以表现得更好
client.deleteByQuery({
index: "_all",
body: { query: { bool: { must: [{ term: { [userProperty]: user } }] } } }
});

关于elasticsearch - 删除具有特定属性值的所有文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57655414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com