我正在尝试构建一个查找所有用户文档(docType = user)的查询,然后根据许多过滤器对其进行过滤.例如位置,性别,年龄等.根据我正在构建的搜索功能的用户输入添加/删除过滤器.
下面没有返回结果:
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": {
"filters":
[
{
"term": {
"doc.docType": "user"
}
},
{
"term": {
"doc.data.profile.location" : "CA"
}
}
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
返回结果如下:
{
"query": {
"filtered": {
"query": {
"field": {
"doc.data.profile.location" : "CA"
}
},
"filter": {
"and": {
"filters":
[
{
"term": {
"doc.docType": "user"
}
}
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
后者虽然返回结果,但从长远来看不会起作用,因为我可能想要为年龄,性别等添加额外的过滤器,我似乎无法添加多个字段.如果我删除了位置过滤器,则第一个查询有效.
任何指导帮助非常感谢.
小智 7
以下是编写多个过滤器查询的方法
{
"query": {
"bool": {
"filter": [
{
"term" : {
"id":254
}
},
{
"term" : {
"cityId":35
}
}
],
"must": [
{
"match_all": {}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17721 次 |
| 最近记录: |