我希望下面的查询返回特定字段中由OR匹配分隔的确切短语的结果。
{
"query": {
"nested": {
"path": "positions",
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "positions.companyname",
"query": "microsoft OR gartner OR IBM"
}
},
{
"query_string": {
"default_field": "positions.title",
"query": "(Chief Information Security Officer) OR (Chief Digital Officer)"
}
}
]
}
},
"inner_hits": {
"highlight": {
"fields": {
"positions.title": {}
}
}
}
}
}
}结果应该包括准确的首席信息安全官或首席数字官,
但不包括首席执行官 Digital 或E 214E 115Information>E 216E 117军官E 218,因为它目前正在返回。
此外,字段可能不一定有要搜索的确切短语。例如:
“首席信息官”->假
“数字主管-首席数字官”->真人
“前首席信息安全官”->真人
“首席信息官”->假
我想我想说的是,这些短语应该永远在一起(接近)。
发布于 2019-04-11 18:00:09
这个查询会完成这个任务。
{
"query": {
"nested": {
"path": "positions",
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "positions.companyname",
"query": "microsoft OR gartner OR IBM"
}
},
{
"bool": {
"should": [
{
"match_phrase": {
"positions.title": "chief information security officer"
}
},
{
"match_phrase": {
"positions.title": "chief digital officer"
}
}
]
}
}
]
}
}
}
}
}match_phrase确保正在搜索确切的短语。若要匹配同一字段上的多个短语,请使用bool运算符和应条件。
https://stackoverflow.com/questions/55636676
复制相似问题