1. 不是""串也不是null

{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must_not": {
              "term": {
                "id": ""
              }
            },
            "must": {
              "exists": {
                "field": "id"
              }
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "id": {
        "order": "asc"
      }
    }
  ]
}
690960906

2. 是""不是null

{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "filter": {
              "term": {
                "id": ""
              }
            },
            "must": {
              "exists": {
                "field": "id"
              }
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "id": {
        "order": "desc"
      }
    }
  ]
}

681695941

3. 是null

4584400
{
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "id"
          }
        }
      ]
    }
  }
}

4. 将空值映射成空串

PUT my-index-000001
{
        "mappings": {
                "properties": {
                        "status_code": {
                        "type": "keyword",
                         "null_value": ""
                        }
                }
        }
}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐