# Wildcards in exact phrase in query\_string search

**URL:** <https://discuss.elastic.co/t/wildcards-in-exact-phrase-in-query-string-search/8515>\
**Category:** Elasticsearch\
**Created:** [July 25, 2012, 4:00pm UTC](https://discuss.elastic.co/t/wildcards-in-exact-phrase-in-query-string-search/8515 "2012-07-25T16:00:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dara](https://avatars.discourse-cdn.com/v4/letter/d/f14d63/32.png) [@Dara](https://discuss.elastic.co/u/Dara)\
**Post date:** [July 25, 2012, 4:00pm UTC](https://discuss.elastic.co/t/wildcards-in-exact-phrase-in-query-string-search/8515/1 "2012-07-25T16:00:44Z")

</div>

Hi,

Is it possible to include wildcards in a query\_string query when looking  
for a phrase?

When I search with the following query :

{  
"query":{  
"query\_string":{  
"default\_operator" : "AND"  
"analyze\_wildcard": true,  
"default\_field":"value",  
"query":""hotel california""  
}  
}

I get some hits which contain the phrase "hotel california" as expected.

However, if I search using

{  
"query":{  
"query\_string":{  
"default\_operator" : "AND"  
"analyze\_wildcard": true,  
"default\_field":"value",  
"query":""hotel c\*""  
}  
}

I get no hits at all.

Does anyone know why this is the case? Is there a workaround?

Cheers,

Dara

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [July 25, 2012, 6:30pm UTC](https://discuss.elastic.co/t/wildcards-in-exact-phrase-in-query-string-search/8515/2 "2012-07-25T18:30:12Z")

</div>

On Wednesday, July 25, 2012 6:00:44 PM UTC+2, Dara wrote:

> Hi,
> 
> Is it possible to include wildcards in a query\_string query when looking  
> for a phrase?
> 
> When I search with the following query :
> 
> {  
> "query":{  
> "query\_string":{  
> "default\_operator" : "AND"  
> "analyze\_wildcard": true,  
> "default\_field":"value",  
> "query":""hotel california""  
> }  
> }
> 
> I get some hits which contain the phrase "hotel california" as expected.
> 
> However, if I search using
> 
> {  
> "query":{  
> "query\_string":{  
> "default\_operator" : "AND"  
> "analyze\_wildcard": true,  
> "default\_field":"value",  
> "query":""hotel c\*""  
> }  
> }

you might wanna look at the text query part of the API. it has a  
text\_prefix\_phrase query that might do what you are looking for.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

simon

> I get no hits at all.
> 
> Does anyone know why this is the case? Is there a workaround?
> 
> Cheers,
> 
> Dara

---

<div class="post-metadata">

**Author:** ![Dara](https://avatars.discourse-cdn.com/v4/letter/d/f14d63/32.png) [@Dara](https://discuss.elastic.co/u/Dara)\
**Post date:** [August 15, 2012, 1:34pm UTC](https://discuss.elastic.co/t/wildcards-in-exact-phrase-in-query-string-search/8515/3 "2012-08-15T13:34:44Z")

</div>

Thanks for the reply, sorry for getting back so late but I've only started  
looking at this again today.

On Wednesday, July 25, 2012 8:30:12 PM UTC+2, simonw wrote:

> On Wednesday, July 25, 2012 6:00:44 PM UTC+2, Dara wrote:
> 
> > Hi,
> > 
> > Is it possible to include wildcards in a query\_string query when looking  
> > for a phrase?
> > 
> > When I search with the following query :
> > 
> > {  
> > "query":{  
> > "query\_string":{  
> > "default\_operator" : "AND"  
> > "analyze\_wildcard": true,  
> > "default\_field":"value",  
> > "query":""hotel california""  
> > }  
> > }
> > 
> > I get some hits which contain the phrase "hotel california" as expected.
> > 
> > However, if I search using
> > 
> > {  
> > "query":{  
> > "query\_string":{  
> > "default\_operator" : "AND"  
> > "analyze\_wildcard": true,  
> > "default\_field":"value",  
> > "query":""hotel c\*""  
> > }  
> > }
> 
> you might wanna look at the text query part of the API. it has a  
> text\_prefix\_phrase query that might do what you are looking for.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html)

I've playing with text\_prefix\_phrase and it seems to be sort of what I'm  
after, but the number of results returned is very dependent on the value of  
max\_expansions and the length of my prefix :

E.g  
{  
"query" : {  
"text\_phrase\_prefix" : {  
"value" : {  
"query" : "Hotel Cali",  
"max\_expansions" : 0  
}  
}  
}  
}

will return some results but

{  
"query" : {  
"text\_phrase\_prefix" : {  
"value" : {  
"query" : "Hotel C",  
"max\_expansions" : 0  
}  
}  
}  
}

won't.

Nor does  
{  
"query" : {  
"text\_phrase\_prefix" : {  
"value" : {  
"query" : "Hotel C",  
"max\_expansions" : 1  
}  
}  
}  
}

Whereas

{  
"query" : {  
"text\_phrase\_prefix" : {  
"value" : {  
"query" : "Hotel C",  
"max\_expansions" : 99  
}  
}  
}  
}

will return some results.

I don't really understand what max\_expansions is doing, and what its value  
actually means, can somebody explain in simple terms? What is being  
expanded? The query? And if that is the case, how is it being expanded?

Thanks,

Dara

simon

> > I get no hits at all.
> > 
> > Does anyone know why this is the case? Is there a workaround?
> > 
> > Cheers,
> > 
> > Dara

--

---

<div class="post-metadata">

**Author:** ![Eric1](https://avatars.discourse-cdn.com/v4/letter/e/3bc359/32.png) [@Eric1](https://discuss.elastic.co/u/Eric1)\
**Post date:** [October 22, 2014, 10:40pm UTC](https://discuss.elastic.co/t/wildcards-in-exact-phrase-in-query-string-search/8515/4 "2014-10-22T22:40:35Z")

</div>

Dara,

Realizing that this is an old post, but I am having this same issue.

Was there a suggested solution that got you through

Eric

---

<div class="post-metadata">

**Author:** ![Dara](https://avatars.discourse-cdn.com/v4/letter/d/f14d63/32.png) [@Dara](https://discuss.elastic.co/u/Dara)\
**Post date:** [October 23, 2014, 7:33am UTC](https://discuss.elastic.co/t/wildcards-in-exact-phrase-in-query-string-search/8515/5 "2014-10-23T07:33:38Z")

</div>

Hi Eric,

I'm sorry but I didn't find a solution. If you do have any luck with this, please post back!

Cheers,

Dara

---

<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:54am UTC](https://discuss.elastic.co/t/wildcards-in-exact-phrase-in-query-string-search/8515/6 "2017-07-06T00:54:18Z")

</div>


