user2742004
user2742004

Reputation: 91

Multiple wildcards in one query in elasticsearch

curl localhost:9200/tweet/posts/_search -d '{
  "query": {
    "and": [
      {
        "wildcard": {
          "_all": "*pet*"
        }
      },
      {
        "wildcard": {
          "_all": "*rom*"
        }
      }
    ]
  }
}'

This gives me a parse exception. I want to run a MySQL like(%test%) type query with an AND condition. Is there any other good way to do in elasticsearch.

Upvotes: 9

Views: 18137

Answers (2)

MichalT
MichalT

Reputation: 49

dis_max query can support wildcard queries not a bool. Please take a look here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html I would write something like this:

{
 "query": {
     "dis_max": {
         "queries": [
               {"wildcard": {
                 "_all": {"value" : "*pet*"}
               }},
               {"wildcard": {
                 "_all": {"value" : "*rom*"}
               }}
           ]
     }
   }
}

Upvotes: 1

Alcanzar
Alcanzar

Reputation: 17165

Maybe something like this?

{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "_all": {
              "value": "*pet*"
            }
          }
        },
        {
          "wildcard": {
            "_all": {
              "value": "*rom*"
            }
          }
        }
      ]
    }
  }
}

Upvotes: 16

Related Questions