嵌套数组的弹性搜索搜索查询

时间:2017-05-29 14:10:00

标签: elasticsearch

{
    "application": {
        "package_name": "com.jackhenry.OregonFirstCU",
         "countries": [
            {
                "short_name": "US"
            }
         ]
},
"application": {
    "package_name": "com.jackhenry.OregonFirstCU",
    "countries": [
        {
            "short_name": "US"
        }
    ]
},
"application": {
        "package_name": "com.jackhenry.OregonFirstCU",
        "countries": [

        ]
    }
}

如何为application.countriesapplication.countries.short_name

获取空数组和美国的结果?

1 个答案:

答案 0 :(得分:0)

简而言之,您希望获取包含美国或不包含任何国家/地区名称的结果。您可以在should之间而不是term

之间应用exists
{
"query": {
  "bool": {
     "should": [
        {
           "bool": {
              "must_not": {
                 "exists": {
                    "field": "application.countries.short_name"
                 }
              }
           }
        },
        {
           "term": {
              "application.countries.short_name": [
                 "US"
              ]
           }
        }
     ]
   }
 }