es 中有两条数据, 字段 item
想通过“match_phrase”搜索“制服”得到第 2 条数据,排除第 1 条数据,以下语句却能得到 2 条数据,请问怎么写才能达到目的?
{ "query": { "bool": { "filter": { "bool": { "should": [ { "match_phrase": { "item": { "query": "制服" } } } ] } }, "must_not": [ { "match_phrase": { "item": { "query": "制服务" } } } ] } }
![]() | 1 Memento 2019-10-22 11:14:06 +08:00 应该可以添加中文分词字段, 然后查询该字段; |
![]() | 2 yuikns 2019-10-22 11:16:50 +08:00 should 和 must_not 同层 |
![]() | 3 herozzm OP @yuikns 也不行 ``` { "query": { "bool": { "should": [ { "match_phrase": { "item": { "query": "制服" } } } ], "must_not": [ { "match_phrase": { "item": { "query": "制服务" } } } ] } } } |
5 airfling 2019-10-22 11:21:51 +08:00 should 换成 must,should 不是强制匹配 |
7 airfling 2019-10-22 11:36:09 +08:00 那你有没有试过这个 missing 的查询 |