【发布时间】:2021-06-08 15:10:22
【问题描述】:
我正在尝试编写一个允许过滤结果集的 ElasticSearch 查询。该应用程序为职位提供了一个过滤器,也为相同的职位提供了一个排除过滤器。所以例如在下面的数据集中,我想过滤Engineer,但也排除Software Engineer。问题是现在查询也排除了Principal Software Engineer,它不应该。
这是我正在使用的数据:
{
"data": [
{
"email": "chris@example.com",
"job_title": "Industrial Electrical Engineer"
},
{
"email": "esther@example.com",
"job_title": "Chief Revenue Officer"
},
{
"email": "george@example.com",
"job_title": "Principal Software Engineer"
},
{
"email": "helena@example.com",
"job_title": "Software Engineer"
},
{
"email": "john@example.com",
"job_title": "Engineer"
},
{
"email": "judith@example.com",
"job_title": "Design Engineer"
},
{
"email": "katy@example.com",
"job_title": "Software Designer"
},
{
"email": "mark@example.com",
"job_title": "Engineer"
},
{
"email": "mary@example.com",
"job_title": "Mechanical Design Engineer"
},
{
"email": "tom@example.com",
"job_title": "Electrical Engineer"
},
{
"email": "tony@example.com",
"job_title": "Chief Executive Officer"
}
]
}
这里是 ElasticSearch 查询:
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"job_title": {
"query": "Engineer",
"operator": "and"
}
}
}
]
}
}
],
"filter": [
{
"term": {
"user_id": 1
}
},
{
"bool": {
"must_not": [
{
"match": {
"job_title": "Software Engineer"
}
}
]
}
}
]
}
}
}
【问题讨论】:
标签: elasticsearch filter