Not able to write the wildcard query for ElasticSearch? Not able to write the wildcard query for ElasticSearch? elasticsearch elasticsearch

Not able to write the wildcard query for ElasticSearch?


This worked for me:

GET /_search{  "query": {    "wildcard": {      "lastname": "aya*"    }  }}

I had wasted many hours until I read this online:

...if you search a not_analyzed field and use wildcards, you MUST NOTinclude any capital letters in your query...

The whole time it was not working because I was searching for e.g. Aya*. Soon as I converted it to lower case aya* it worked.


I'm guessing your lastname field is probably analyzed and thus the token that was indexed is ayala and not Ayala. So since wildcard queries are not analyzed you need to specify the search term in lowercase:

Try this:

POST /_search{    "query":{           "filtered" : {      "filter" : {        "bool" : {          "should" :          {            "wildcard":{"lastname" : "aya*" }          }              }      }    }    }}