弹性搜索

时间:2018-03-30 09:28:37

标签: elasticsearch filter

我想获得国家/地区代码为USCA的所有条目。我通过以下方式准备我的查询,但获得零号码或记录,而不是按国家/地区代码USCA

获取te记录

方式1

GET my_index/_search
{
   "query" : {
      "bool" : {
         "filter" : {
            "terms" : {
              "country_code" : ["CA","US"]
            }
         }
      }
   }
}

方式2

GET my_index/_search
{
   "query" : {
      "bool" : {
         "must" : {
            "terms" : {
              "country_code" : ["CA","US"]
            }
         }
      }
   }
}

你能帮我查一下我的查询错误吗?

1 个答案:

答案 0 :(得分:0)

我使用小写

获得了我的解决方案
GET my_index/_search
{
  "query": {
    "bool": {
      "filter": [
        {"terms": {"country_code": ["us","ca"]}}
      ]
    }
  }
}