Elastic query DSL: Wildcards in terms filter?

前端 未结 1 1590
臣服心动
臣服心动 2021-02-05 05:25

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\":         


        
相关标签:
1条回答
  • 2021-02-05 05:36

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

    UPDATE:

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

    {
      "query": {
        "bool": {
          "filter": {
             "regexp": {
               "aircraft": "a380.*"
             }
          }
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题