Filter Query Missing 已经从 ES 5 版本移除
Refer to:
https://www.elastic.co/guide/en/elasticsearch/reference/6.1/query-dsl-exists-query.html#_literal_missing_literal_query
There isn’t a `missing` query. Instead use the `exists` query inside a `must_not` clause as follows:
GET /_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "user"
}
}
}
}
}
针对 ES 5.2.2 之前版本(如 ES 2.3.4),查询不包含某字段(无 content 字段)的数据, 支持使用 missing 或者 exists,DSL 如下:
### 不适用于 ES5.2.2 及以上版本
{
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"bool": {
"must": [
{
"match_phrase": {
"title": {
"query": "华为",
"slop": 0
}
}
}
]
}
}
]
}
},
{
"missing": {
"field": "content"
}
},
{
"range": {
"pubTime": {
"from": 1514736000000,
"to": 1517414400000,
"include_lower": true,
"include_upper": false
}
}
}
]
}
}
}
针对 ES 5.2.2 以上版本,查询不包含某字段(无 content 字段)的数据,DSL 如下:
### 高低版本通用
{
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"bool": {
"must": [
{
"match_phrase": {
"title": {
"query": "华为",
"slop": 0
}
}
}
]
}
}
]
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "content"
}
}
}
},
{
"range": {
"pubTime": {
"from": 1514736000000,
"to": 1517414400000,
"include_lower": true,
"include_upper": false
}
}
}
]
}
}
}