我正在使用弹性搜索,带有查询 match_all 和过滤。在我的情况下,我想应用通用过滤器并按条件过滤。
这里是伪的:
- 查询:匹配所有(工作正常)
- 过滤 d1 和 d2 之间的日期范围(没有项目符号 3 也能正常工作)
- 过滤器(仅在字段存在时应用,但如何应用?)
- etc.
请参阅以下代码。如果“组”字段存在,我只想应用“组”过滤器!在这种情况下,“存在”过滤器不会生效。
"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]}
}
}
}
}
}
}
}
}
}
Try this
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"range": {
"date": {
"from": "2015-06-01",
"to": "2015-06-30"
}
}
},
{
"bool": {
"should": [
{
"missing": {
"field": "groups"
}
},
{
"bool": {
"must": {
"term": {
"groups.sex": "w"
}
},
"should": {
"terms": {"groups.categories.id": [7,10]}
}
}
}
]
}
}
],
"must_not": {
"term": {
"e.state": 0
}
}
}
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)