我需要使用以下规则集来构建搜索查询。
例如,如果我在索引中有1000条记录,其中70%的记录具有active = true,而30%的记录具有active = false。在30%的记录中,有10%最近更新。所以我只需要获取记录的80%,即70%(active = true)+ 10%(active = false)。
我尝试使用过滤器查询,但它只返回结果的10%,即仅满足规则2,即使我在应该阻止的规则中提到了规则1也不会接受。
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"range": {
"UpdatedOn": {
"gte": "now-7d/d",
"lte": "now/d"
}
}
},
{
"match": {
"Active": "false"
}
}
]
}
},
"should": [
{
"match": {
"Active": "true"
}
}
]
}
}
}
ElasticSearch 5.4版
提前致谢。
最佳答案
您需要这样做:
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"match": {
"Active": "true"
}
},
{
"bool": {
"filter": [
{
"range": {
"UpdatedOn": {
"gte": "now-7d/d",
"lte": "now/d"
}
}
},
{
"match": {
"Active": "false"
}
}
]
}
}
]
}
}
}
关于elasticsearch - ElasticSearch搜索查询中的多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50969880/