弹性查询DSL:用通配符过滤吗? [英] Elastic query DSL: Wildcards in terms filter?

查看:137
本文介绍了弹性查询DSL:用通配符过滤吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用术语过滤器过滤文档。我不确定如何在过滤器中引入通配符。我尝试过这样的事情:

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*"
                ]
             }
         }
      }
   }
}

但是我明白了SearchParseException与此。在筛选器框架中没有办法使用通配符?

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

推荐答案

术语过滤器不支持通配符,但是查询支持。而是尝试以下查询

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

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

或者如果您绝对需要使用过滤器,则可以尝试 regexp 过滤器:

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

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

更新

在最新的ES版本中,请使用以下查询,因为已过滤已被删除:

In latest ES versions, use the following query instead since filtered has been removed:

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

这篇关于弹性查询DSL:用通配符过滤吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆