# Wildcards in Phrases and Proximity searches

**URL:** https://discuss.elastic.co/t/wildcards-in-phrases-and-proximity-searches/6798
**Category:** Elasticsearch
**Created:** [February 24, 2012, 11:58am UTC](https://discuss.elastic.co/t/wildcards-in-phrases-and-proximity-searches/6798 "2012-02-24T11:58:54Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Christian\_von\_Wendt\_](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@Christian\_von\_Wendt\_](https://discuss.elastic.co/u/Christian_von_Wendt_)
#### Post date: [February 24, 2012, 11:58am UTC](https://discuss.elastic.co/t/wildcards-in-phrases-and-proximity-searches/6798/1 "2012-02-24T11:58:54Z")

</div>

Hi,

I was wondering if it is possible to specify wildcards in a phrase/  
proximity search such as:

"elastic\* searchengine" which would search for any two words where the  
first starts with "elastic" and the other is "searchengine".

For proximity (NEAR) a search could look like this:

"elastic\* searchengine"^5 which would return document where two words  
exists in proximity of 5 words distance and the first starts with  
"elastic".

---

<div class="post-metadata">

### Author: ![Christian\_von\_Wendt\_](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@Christian\_von\_Wendt\_](https://discuss.elastic.co/u/Christian_von_Wendt_)
#### Post date: [March 13, 2012, 8:47am UTC](https://discuss.elastic.co/t/wildcards-in-phrases-and-proximity-searches/6798/2 "2012-03-13T08:47:13Z")

</div>

No suggestions, anyone?

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [March 13, 2012, 9:34am UTC](https://discuss.elastic.co/t/wildcards-in-phrases-and-proximity-searches/6798/3 "2012-03-13T09:34:31Z")

</div>

> For proximity (NEAR) a search could look like this:
> 
> "elastic\* searchengine"^5 which would return document where two words  
> exists in proximity of 5 words distance and the first starts with  
> "elastic".

Actually, that syntax boosts the phrase, it doesn't imply a proximity  
search. See  
[http://lucene.apache.org/core/old\_versioned\_docs/versions/3\_5\_0/queryparsersyntax.html](http://lucene.apache.org/core/old_versioned_docs/versions/3_5_0/queryparsersyntax.html)

What you want is: (elastic\* searchengine)^5

and yes it does support wildcards

clint

>

---

<div class="post-metadata">

### Author: ![Christian\_von\_Wendt\_](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@Christian\_von\_Wendt\_](https://discuss.elastic.co/u/Christian_von_Wendt_)
#### Post date: [March 14, 2012, 7:54am UTC](https://discuss.elastic.co/t/wildcards-in-phrases-and-proximity-searches/6798/4 "2012-03-14T07:54:33Z")

</div>

Hi,

Well - I made a mistake using the wrong operator, confusing everybody with  
my example. I do not want to boost the query. Rather I want to find  
document where two or more terms are in proximity of each other, and where  
one or more of the terms are wildcard-terms. My example should have been  
something like:

"elastic\* searchengine"~5

Is this possible?

Regards,

Christian

Den tirsdag den 13. marts 2012 10.34.31 UTC+1 skrev Clinton Gormley:

> > For proximity (NEAR) a search could look like this:
> > 
> > "elastic\* searchengine"^5 which would return document where two words  
> > exists in proximity of 5 words distance and the first starts with  
> > "elastic".
> 
> Actually, that syntax boosts the phrase, it doesn't imply a proximity  
> search. See
> 
> [Apache Lucene - Query Parser Syntax](http://lucene.apache.org/core/old_versioned_docs/versions/3_5_0/queryparsersyntax.html)
> 
> What you want is: (elastic\* searchengine)^5
> 
> and yes it does support wildcards
> 
> clint
> 
> >

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [March 14, 2012, 9:46am UTC](https://discuss.elastic.co/t/wildcards-in-phrases-and-proximity-searches/6798/5 "2012-03-14T09:46:55Z")

</div>

> Well - I made a mistake using the wrong operator, confusing everybody  
> with my example. I do not want to boost the query. Rather I want to  
> find document where two or more terms are in proximity of each other,  
> and where one or more of the terms are wildcard-terms. My example  
> should have been something like:
> 
> "elastic\* searchengine"~5

Sorry, yes, that's what I mean too.

> Is this possible?

Did you try it?

clint

> Regards,
> 
> Christian
> 
> Den tirsdag den 13. marts 2012 10.34.31 UTC+1 skrev Clinton Gormley:  
> \> For proximity (NEAR) a search could look like this:  
> \>  
> \> "elastic\* searchengine"^5 which would return document where  
> two words  
> \> exists in proximity of 5 words distance and the first starts  
> with  
> \> "elastic".
> 
> ```
> Actually, that syntax boosts the phrase, it doesn't imply a
> proximity
> search. See
> http://lucene.apache.org/core/old_versioned_docs/versions/3_5_0/queryparsersyntax.html
>     
> What you want is: (elastic* searchengine)^5
>     
> and yes it does support wildcards
>     
> clint
>     
> > 
> > 
> > 
> 
> ```

---

<div class="post-metadata">

### Author: ![Christian\_von\_Wendt\_](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@Christian\_von\_Wendt\_](https://discuss.elastic.co/u/Christian_von_Wendt_)
#### Post date: [March 14, 2012, 12:05pm UTC](https://discuss.elastic.co/t/wildcards-in-phrases-and-proximity-searches/6798/6 "2012-03-14T12:05:32Z")

</div>

Hi again,

Yes, I've tried both version. In this version:

_(elastic_ searchengine)~5  
\*  
I get a parseException, while this version:

_"elastic_ searchengine"~5  
\*  
simply ignores the wildcard part.

Den onsdag den 14. marts 2012 10.46.55 UTC+1 skrev Clinton Gormley:

> > Well - I made a mistake using the wrong operator, confusing everybody  
> > with my example. I do not want to boost the query. Rather I want to  
> > find document where two or more terms are in proximity of each other,  
> > and where one or more of the terms are wildcard-terms. My example  
> > should have been something like:
> > 
> > "elastic\* searchengine"~5
> 
> Sorry, yes, that's what I mean too.
> 
> > Is this possible?
> 
> Did you try it?
> 
> clint
> 
> > Regards,
> > 
> > Christian
> > 
> > Den tirsdag den 13. marts 2012 10.34.31 UTC+1 skrev Clinton Gormley:  
> > \> For proximity (NEAR) a search could look like this:  
> > \>  
> > \> "elastic\* searchengine"^5 which would return document where  
> > two words  
> > \> exists in proximity of 5 words distance and the first starts  
> > with  
> > \> "elastic".
> > 
> > ```
> > Actually, that syntax boosts the phrase, it doesn't imply a
> > proximity
> > search. See
> > 
> > ```
> 
> [Apache Lucene - Query Parser Syntax](http://lucene.apache.org/core/old_versioned_docs/versions/3_5_0/queryparsersyntax.html)
> 
> > ```
> > What you want is: (elastic* searchengine)^5
> >     
> > and yes it does support wildcards
> >     
> > clint
> >     
> > > 
> > > 
> > > 
> > 
> > ```

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [March 14, 2012, 12:18pm UTC](https://discuss.elastic.co/t/wildcards-in-phrases-and-proximity-searches/6798/7 "2012-03-14T12:18:39Z")

</div>

On Wed, 2012-03-14 at 05:05 -0700, Christian von Wendt-Jensen wrote:

> Hi again,
> 
> Yes, I've tried both version. In this version:
> 
> (elastic\* searchengine)~5
> 
> I get a parseException, while this version:
> 
> "elastic\* searchengine"~5
> 
> simply ignores the wildcard part.

Yes, as the docs say:

```
    Lucene supports single and multiple character wildcard searches
    within single terms (not within phrase queries).

```

[http://lucene.apache.org/core/old\_versioned\_docs/versions/3\_4\_0/queryparsersyntax.html#Wildcard%20Searches](http://lucene.apache.org/core/old_versioned_docs/versions/3_4_0/queryparsersyntax.html#Wildcard%20Searches)

> 

So it looks like you are out of luck

I've tried to think of a way you could achieve this using ngrams or edge  
ngrams, but you couldn't wildcard a single word in the phrase.

clint

---

<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, 3:36am UTC](https://discuss.elastic.co/t/wildcards-in-phrases-and-proximity-searches/6798/8 "2017-07-06T03:36:13Z")

</div>


