# How do I query using Wildcard

**URL:** <https://discuss.elastic.co/t/how-do-i-query-using-wildcard/2654>\
**Category:** Elasticsearch\
**Created:** [June 14, 2015, 9:41pm UTC](https://discuss.elastic.co/t/how-do-i-query-using-wildcard/2654 "2015-06-14T21:41:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drammy](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@Drammy](https://discuss.elastic.co/u/Drammy)\
**Post date:** [June 14, 2015, 9:41pm UTC](https://discuss.elastic.co/t/how-do-i-query-using-wildcard/2654/1 "2015-06-14T21:41:14Z")

</div>

Hi all,

I have a query that I've got working nicely but returns no data if I use a wildcard.

Do I have to enable wildcards somewhere or should I be using the wildcard query instead?

If I need to use the wildcard query then I need to start detecting wildcards in the user's search phrase and then alter the query - I don't like the idea of that so any help appreciated...?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 14, 2015, 11:12pm UTC](https://discuss.elastic.co/t/how-do-i-query-using-wildcard/2654/2 "2015-06-14T23:12:44Z")

</div>

What does the query look like?

---

<div class="post-metadata">

**Author:** ![Drammy](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@Drammy](https://discuss.elastic.co/u/Drammy)\
**Post date:** [June 15, 2015, 9:02am UTC](https://discuss.elastic.co/t/how-do-i-query-using-wildcard/2654/3 "2015-06-15T09:02:42Z")

</div>

The simplified query below works

```
GET contacts/_search
{
    "query": {
      "bool": {
        "should": [ 
          {"nested": {
            "path": "organisation",
            "query": {
              "bool": {
                "should": [
                    {"multi_match": {
                  "query": "te",
                  "fields": ["organisation.name"],
                  "type": "best_fields"
                }},
                {"nested": {
                  "path": "screenData",
                  "query": {
                    "multi_match": {
                      "query": "advertising",
                      "fields": ["screenData.valueString"],
                      "type": "best_fields"
                    }
                  }
                }}
                ]
              }
            }
          }
        }]
      } 
    }
}

```

but a wildcarded equivalent doesn't..

```
GET contacts/_search
{
    "query": {
      "bool": {
        "should": [ 
          {"nested": {
            "path": "organisation",
            "query": {
              "bool": {
                "should": [
                    {"multi_match": {
                  "query": "te",
                  "fields": ["organisation.name"],
                  "type": "best_fields"
                }},
                {"nested": {
                  "path": "screenData",
                  "query": {
                    "multi_match": {
                      "query": "advertis*",
                      "fields": ["screenData.valueString"],
                      "type": "best_fields"
                    }
                  }
                }}
                ]
              }
            }
          }
        }]
      } 
    }
}

```

I have the screenData.valueString field analysed with the english analyser but have tried standard and not\_analysed with the same results: no records.

---

<div class="post-metadata">

**Author:** ![Drammy](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@Drammy](https://discuss.elastic.co/u/Drammy)\
**Post date:** [June 17, 2015, 8:53am UTC](https://discuss.elastic.co/t/how-do-i-query-using-wildcard/2654/4 "2015-06-17T08:53:51Z")

</div>

Anyone got any ideas how I can avoid having to use a specific wildcard query - I thought I could just use wildcards in all query types?

Is there a setting I need to enable somewhere?

---

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [June 17, 2015, 10:03am UTC](https://discuss.elastic.co/t/how-do-i-query-using-wildcard/2654/5 "2015-06-17T10:03:09Z")

</div>

The `match` and `multi_match` queries do not support wildcards. In general you should avoid using wildcards in your queries as they are not efficient. A more efficient solution would be to index the fields using `ngrams`.

If you can't use `ngrams` and need to use a wildcard query this will do what you want:

```
{
  "query":{
	"bool":{
	  "should":[
		{
		  "nested":{
			"path":"organisation",
			"query":{
			    "multi_match":{
				"query":"te",
				"fields":[
				  "organisation.name"
				],
				"type":"best_fields"
			    }
			}
		  }
		},
		{
		  "nested":{
		      "path":"screenData",
		         "query":{
			     "wildcard":{
				"screenData.valueString":"advertis*"
			     }
			 }
		     } 
		}
	    ]
	}
    }
}
```

---

<div class="post-metadata">

**Author:** ![Drammy](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@Drammy](https://discuss.elastic.co/u/Drammy)\
**Post date:** [June 17, 2015, 11:02am UTC](https://discuss.elastic.co/t/how-do-i-query-using-wildcard/2654/6 "2015-06-17T11:02:41Z")

</div>

OK, thanks - that's a shame as I was wanting to allow "power-users" the ability to use wildcards and phrase searching with double-quotes etc... a la Google.

So its a detect & query rewrite then - pity!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:07am UTC](https://discuss.elastic.co/t/how-do-i-query-using-wildcard/2654/7 "2017-07-06T00:07:03Z")

</div>


