查询字段为空值

时间:2014-04-17 21:29:23

标签: elasticsearch

我试图查询空字段。用SQL的说法,我会做以下几点:

 select * from cars where cartype="Auto" and make="Ferrari" and color="" and model="" and seats in ["", "bench"]

我正在执行以下操作,但我收到了错误

 {
     "query": {
         "bool": {
             "must": [
                 {
                     "match": {
                         "CarType": "Auto"
                     }
                 },
                 {
                     "match": {
                         "Make": "Ferrari"
                     }
                 }
             ],
             "must_not": [
                 {
                     "existence": true,
                     "field": "Color",
                     "null_value": true
                 },
                 {
                     "existence": true,
                     "field": "Model",
                     "null_value": true
                 }
             ]
         }
     }
 }

但是我得到以下内容:"解析失败[无法解析源代码....链接:查询格式错误"

我跟随示例here

1 个答案:

答案 0 :(得分:0)

试试这个

{
"query": {
    "bool": {
        "must": [

                {
                 "match": {
                     "CarType": "Auto"
                 }
                }
          ,
          {
                 "match": {
                     "Make": "Ferrari"
                 }

           }
        ], "must_not": [
           {
              "missing":{
                        "field":"Model",
                         "existence":true,
                          "null_value":true
                         }
           },
            {
              "missing":{
                        "field":"Color",
                         "existence":true,
                          "null_value":true
                         }
           }
        ]
    }
}
}