Elastic query DSL: Wildcards in terms filter?

只愿长相守 提交于 2019-12-03 11:21:53

问题


I am trying to filter the documents using terms filter. I am not sure how to introduce wildcards in filter. I tried something like this:

"filter":{
  "bool":{
       "must":{
          "terms":{
             "wildcard" :  {
                "aircraft":[
                   "a380*"
                ]
             }
         }
      }
   }
}

But I get SearchParseException with this. Is there no way to use wildcard within filter framework?


回答1:


The terms filter doesn't support wildcards, queries do, though. Try this query instead

{
  "query": {
    "bool": {
      "must": {
        "wildcard": {
          "aircraft": "a380*"
        }
      }
    }
  }
}

Or if you absolutely need to use filters, you can try the regexp filter, too:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": {
            "regexp": {
              "aircraft": "a380.*"
            }
          }
        }
      }
    }
  }
}


来源:https://stackoverflow.com/questions/30473653/elastic-query-dsl-wildcards-in-terms-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!