Elasticsearch使用过滤器布尔值或查询查询ID [英] Elasticsearch querying ids with a filter boolean or query
问题描述
我有一个查询,该查询应该获取与这些ID之一匹配的任何行.查询不返回任何内容,但应返回两行.如果删除一个ID,我将返回上一行.我假设它正在执行AND运算符,而不是OR运算符.我该如何更改?(实际上,我还有很多要查询的ID)
I have a query that should be getting any row that matches one of these ids. The query returns nothing, but should return two rows. If I remove one id I get one row back. I'm assuming it's doing an AND rather than an OR. How can I change this? (In practice I have many more ids to query)
{
"query": {
"bool": {
"filter": [
{
"term": {
"_id": 1273359
}
},
{
"term": {
"_id": 480421
}
}
]
}
}
}
推荐答案
Try the ids
filter instead
{
"query": {
"bool": {
"filter": [
{
"ids": {
"values": ["1273359", "480421"]
}
}
]
}
}
}
请注意,您所查询的意思是查找ID为1273359 AND 1273359的文档",实际上这是不可能的.使用上面的查询,您将拥有一个OR或一个AND,它将可以正常工作.
Note that the query you had meant "find documents whose id is 1273359 AND 1273359", which is not possible in practice. With the above query, you have an OR instead of a AND and it will work.
这篇关于Elasticsearch使用过滤器布尔值或查询查询ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!