【发布时间】:2023-03-31 05:36:01
【问题描述】:
我使用的是 Elastic Search,带有查询 match_all 和过滤。在我的情况下,我想应用一般过滤器并按条件过滤。
这里是伪:
- 查询:匹配所有(工作正常)
- 过滤 d1 和 d2 之间的日期范围(没有项目符号 3 可以正常工作)
- 过滤器(仅在字段存在时应用,但如何?)
- 等
请参阅以下代码。如果“组”字段存在,我只想应用“组”过滤器! “exists”过滤器在这种情况下不起作用。
"query":
{
"filtered":
{
"query":
{
"match_all": {}
},
"filter":
{
"bool":
{
"must":
{
"range":
{
"date": {
"from": "2015-06-01",
"to": "2015-06-30"
}
}
},
"must_not":
{
"term":
{
"e.state": 0
}
}
}
},
"filter":
{
"bool":
{
"must":
{
"exists": {"field": "groups"},
"filter":
{
"bool":
{
"must":
{
"term": {"groups.sex": "w"}
},
"should":
{
"terms": {"groups.categories.id": [7,10]}
}
}
}
}
}
}
}
}
}
【问题讨论】:
标签: elasticsearch conditional apply exists