# Regexp in query\_string not returning a matching document

**URL:** <https://discuss.elastic.co/t/regexp-in-query-string-not-returning-a-matching-document/7496>\
**Category:** Elasticsearch\
**Created:** [April 27, 2012, 4:35pm UTC](https://discuss.elastic.co/t/regexp-in-query-string-not-returning-a-matching-document/7496 "2012-04-27T16:35:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin\_Boutros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_boutros/32/1727_2.png) [@Robin\_Boutros](https://discuss.elastic.co/u/Robin_Boutros)\
**Post date:** [April 27, 2012, 4:35pm UTC](https://discuss.elastic.co/t/regexp-in-query-string-not-returning-a-matching-document/7496/1 "2012-04-27T16:35:27Z")

</div>

I'm searching with this simple query (autocompletion feature)

{ query { string "title:#{keywords}\*" } }

Let's say I have a document with the title: Eliminate texting while driving.

- If keywords is elimin then the document is returned.
- If keywords is elimina then it's not!

What am I missing? Is there some kind of "max distance" for \*?

Thanks!

ps: you can also answer on stackoverflow if you  
want: [http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document](http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document)

---

<div class="post-metadata">

**Author:** ![Robin\_Boutros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_boutros/32/1727_2.png) [@Robin\_Boutros](https://discuss.elastic.co/u/Robin_Boutros)\
**Post date:** [April 27, 2012, 4:43pm UTC](https://discuss.elastic.co/t/regexp-in-query-string-not-returning-a-matching-document/7496/2 "2012-04-27T16:43:29Z")

</div>

Forgot to say I was using Tire. It would translate to something like:

query\_string: {  
default\_field: title  
query: elimin\*  
}

But using Elasticsearch Head, I actually noticed that the "\*" is useless.  
"elimin" will match Eliminate texting while driving but "elimina" won't.  
Could you tell me why?

On Friday, April 27, 2012 12:35:27 PM UTC-4, Robin Boutros wrote:

> I'm searching with this simple query (autocompletion feature)
> 
> { query { string "title:#{keywords}\*" } }
> 
> Let's say I have a document with the title: Eliminate texting while  
> driving.
> 
> - If keywords is elimin then the document is returned.
> - If keywords is elimina then it's not!
> 
> What am I missing? Is there some kind of "max distance" for \*?
> 
> Thanks!
> 
> ps: you can also answer on stackoverflow if you want:  
> [http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document](http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document)

On Friday, April 27, 2012 12:35:27 PM UTC-4, Robin Boutros wrote:

> I'm searching with this simple query (autocompletion feature)
> 
> { query { string "title:#{keywords}\*" } }
> 
> Let's say I have a document with the title: Eliminate texting while  
> driving.
> 
> - If keywords is elimin then the document is returned.
> - If keywords is elimina then it's not!
> 
> What am I missing? Is there some kind of "max distance" for \*?
> 
> Thanks!
> 
> ps: you can also answer on stackoverflow if you want:  
> [http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document](http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document)

---

<div class="post-metadata">

**Author:** ![Robin\_Boutros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_boutros/32/1727_2.png) [@Robin\_Boutros](https://discuss.elastic.co/u/Robin_Boutros)\
**Post date:** [April 27, 2012, 5:02pm UTC](https://discuss.elastic.co/t/regexp-in-query-string-not-returning-a-matching-document/7496/3 "2012-04-27T17:02:51Z")

</div>

Oh... I get it, it's because I'm using the snowball analyzer... So it comes  
back to my original question of why the \* doesnt work in my case...

On Friday, April 27, 2012 12:35:27 PM UTC-4, Robin Boutros wrote:

> I'm searching with this simple query (autocompletion feature)
> 
> { query { string "title:#{keywords}\*" } }
> 
> Let's say I have a document with the title: Eliminate texting while  
> driving.
> 
> - If keywords is elimin then the document is returned.
> - If keywords is elimina then it's not!
> 
> What am I missing? Is there some kind of "max distance" for \*?
> 
> Thanks!
> 
> ps: you can also answer on stackoverflow if you want:  
> [http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document](http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document)

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 28, 2012, 3:37am UTC](https://discuss.elastic.co/t/regexp-in-query-string-not-returning-a-matching-document/7496/4 "2012-04-28T03:37:35Z")

</div>

I think you already answered your question - it's because you are using  
snowball analyzer. The snowball analyzer converts Eliminate into term elimin

$ curl "localhost:9200/myindex/\_analyze?text=Eliminate&analyzer=snowball"  
{"tokens":[{"token":"elimin","start\_offset":0,"end\_offset":9,"type":"","position":1}]}

The query elimina\* searches for terms that start with elimina, and there  
are no such terms in the index. By default, wildcard terms are not analyzed

- they are only converted to lower case.

On Friday, April 27, 2012 1:02:51 PM UTC-4, Robin Boutros wrote:

> Oh... I get it, it's because I'm using the snowball analyzer... So it  
> comes back to my original question of why the \* doesnt work in my case...
> 
> On Friday, April 27, 2012 12:35:27 PM UTC-4, Robin Boutros wrote:
> 
> > I'm searching with this simple query (autocompletion feature)
> > 
> > { query { string "title:#{keywords}\*" } }
> > 
> > Let's say I have a document with the title: Eliminate texting while  
> > driving.
> > 
> > - If keywords is elimin then the document is returned.
> > - If keywords is elimina then it's not!
> > 
> > What am I missing? Is there some kind of "max distance" for \*?
> > 
> > Thanks!
> > 
> > ps: you can also answer on stackoverflow if you want:  
> > [http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document](http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document)

---

<div class="post-metadata">

**Author:** ![Robin\_Boutros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_boutros/32/1727_2.png) [@Robin\_Boutros](https://discuss.elastic.co/u/Robin_Boutros)\
**Post date:** [April 28, 2012, 3:56am UTC](https://discuss.elastic.co/t/regexp-in-query-string-not-returning-a-matching-document/7496/5 "2012-04-28T03:56:39Z")

</div>

Indeed... I changed it to the standard analyzer and it's fine.

Thanks 🙂

On Friday, April 27, 2012 11:37:35 PM UTC-4, Igor Motov wrote:

> I think you already answered your question - it's because you are using  
> snowball analyzer. The snowball analyzer converts Eliminate into term elimin
> 
> $ curl "localhost:9200/myindex/\_analyze?text=Eliminate&analyzer=snowball"
> 
> {"tokens":[{"token":"elimin","start\_offset":0,"end\_offset":9,"type":"","position":1}]}
> 
> The query elimina\* searches for terms that start with elimina, and there  
> are no such terms in the index. By default, wildcard terms are not analyzed
> 
> - they are only converted to lower case.
> 
> On Friday, April 27, 2012 1:02:51 PM UTC-4, Robin Boutros wrote:
> 
> > Oh... I get it, it's because I'm using the snowball analyzer... So it  
> > comes back to my original question of why the \* doesnt work in my case...
> > 
> > On Friday, April 27, 2012 12:35:27 PM UTC-4, Robin Boutros wrote:
> > 
> > > I'm searching with this simple query (autocompletion feature)
> > > 
> > > { query { string "title:#{keywords}\*" } }
> > > 
> > > Let's say I have a document with the title: Eliminate texting while  
> > > driving.
> > > 
> > > - If keywords is elimin then the document is returned.
> > > - If keywords is elimina then it's not!
> > > 
> > > What am I missing? Is there some kind of "max distance" for \*?
> > > 
> > > Thanks!
> > > 
> > > ps: you can also answer on stackoverflow if you want:  
> > > [http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document](http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document)

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 29, 2012, 5:28pm UTC](https://discuss.elastic.co/t/regexp-in-query-string-not-returning-a-matching-document/7496/6 "2012-04-29T17:28:25Z")

</div>

Note, to do autocomplete, its is not recommended to use wildcard (or  
prefix) query, you can index the data using with an analyzer based on edge  
ngram (and use standard analyzer for search), which will provide better /  
faster results (though a bigger index).

On Sat, Apr 28, 2012 at 6:56 AM, Robin Boutros [niuage@gmail.com](mailto:niuage@gmail.com) wrote:

> Indeed... I changed it to the standard analyzer and it's fine.
> 
> Thanks 🙂
> 
> On Friday, April 27, 2012 11:37:35 PM UTC-4, Igor Motov wrote:
> 
> > I think you already answered your question - it's because you are using  
> > snowball analyzer. The snowball analyzer converts Eliminate into term elimin
> > 
> > $ curl "localhost:9200/myindex/\_ **analyze?text=Eliminate&**  
> > analyzer=snowball"  
> > {"tokens":[{"token":"elimin"," **start\_offset":0,"end\_offset":**  
> > 9,"type":"","\*\*position":1}]}
> > 
> > The query elimina\* searches for terms that start with elimina, and there  
> > are no such terms in the index. By default, wildcard terms are not analyzed
> > 
> > - they are only converted to lower case.
> > 
> > On Friday, April 27, 2012 1:02:51 PM UTC-4, Robin Boutros wrote:
> > 
> > > Oh... I get it, it's because I'm using the snowball analyzer... So it  
> > > comes back to my original question of why the \* doesnt work in my case...
> > > 
> > > On Friday, April 27, 2012 12:35:27 PM UTC-4, Robin Boutros wrote:
> > > 
> > > > I'm searching with this simple query (autocompletion feature)
> > > > 
> > > > { query { string "title:#{keywords}\*" } }
> > > > 
> > > > Let's say I have a document with the title: Eliminate texting while  
> > > > driving.
> > > > 
> > > > - If keywords is elimin then the document is returned.
> > > > - If keywords is elimina then it's not!
> > > > 
> > > > What am I missing? Is there some kind of "max distance" for \*?
> > > > 
> > > > Thanks!
> > > > 
> > > > ps: you can also answer on stackoverflow if you want:  
> > > > [http://stackoverflow](http://stackoverflow). **com/questions/10354002/**  
> > > > elasticsearch-tire-regexp-in- **query-string-not-returning-a-**  
> > > > matching-document[http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document](http://stackoverflow.com/questions/10354002/elasticsearch-tire-regexp-in-query-string-not-returning-a-matching-document)

---

<div class="post-metadata">

**Author:** ![Robin\_Boutros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_boutros/32/1727_2.png) [@Robin\_Boutros](https://discuss.elastic.co/u/Robin_Boutros)\
**Post date:** [April 29, 2012, 6:22pm UTC](https://discuss.elastic.co/t/regexp-in-query-string-not-returning-a-matching-document/7496/7 "2012-04-29T18:22:49Z")

</div>

That's exactly what I ended up with kimchy!

This stackoverflow answer was pretty helpful, just in case someone is  
interested in doing that as  
well: [http://stackoverflow.com/questions/9421358/filename-search-with-elasticsearch](http://stackoverflow.com/questions/9421358/filename-search-with-elasticsearch)

Thanks

---

<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:30am UTC](https://discuss.elastic.co/t/regexp-in-query-string-not-returning-a-matching-document/7496/8 "2017-07-06T03:30:36Z")

</div>


