咨询Elasticsearch 8.9版本中not子句的对应替代语法
Elasticsearch 8.9 替代
not 子句的语法 在 Elasticsearch 8.9 版本中,not 查询已被移除,需通过 bool 查询的 must_not 子句 实现原有的否定过滤逻辑。
原 Elasticsearch 2.2 可运行语法
{ "bool" : { "must" : { "term" : { "name.first" : "shay" } }, "filter" : { "not" : { "range" : { "postDate" : { "from" : "2010-03-01", "to" : "2010-04-01" } } } } } }
适配 Elasticsearch 8.9 的替代语法
{ "bool" : { "must" : { "term" : { "name.first" : "shay" } }, "filter" : { "bool": { "must_not": { "range" : { "postDate" : { "gte" : "2010-03-01", "lte" : "2010-04-01" } } } } } } }
关键修改说明
- 把原
filter内的not结构替换为bool.must_not,这是高版本 Elasticsearch 标准的否定查询写法。 - 补充:
range查询的from/to在新版本中仍兼容,但更推荐使用gte/lte(大于等于/小于等于)来提升语法可读性。
内容的提问来源于stack exchange,提问作者Ajay Takur
相关产品推荐
相关产品推荐

