Filter Query Missing 已經(jīng)從 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"
}
}
}
}
}
針對(duì) ES 5.2.2 之前版本(如 ES 2.3.4),查詢不包含某字段(無(wú) content 字段)的數(shù)據(jù), 支持使用 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
}
}
}
]
}
}
}
針對(duì) ES 5.2.2 以上版本,查詢不包含某字段(無(wú) content 字段)的數(shù)據(jù),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
}
}
}
]
}
}
}