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

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐