# Relevation on wildcard results and wildcard speed

**URL:** <https://discuss.elastic.co/t/relevation-on-wildcard-results-and-wildcard-speed/4469>\
**Category:** Elasticsearch\
**Created:** [May 24, 2011, 6:32pm UTC](https://discuss.elastic.co/t/relevation-on-wildcard-results-and-wildcard-speed/4469 "2011-05-24T18:32:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@Michael](https://discuss.elastic.co/u/Michael)\
**Post date:** [May 24, 2011, 6:32pm UTC](https://discuss.elastic.co/t/relevation-on-wildcard-results-and-wildcard-speed/4469/1 "2011-05-24T18:32:48Z")

</div>

Hi guys!  
I want to do something like this.  
When I search for example on field first\_name by wildcard "_A_" I want  
to see my result sortable like this

Andrew  
Frank  
Michael  
Brenda

Can I do this by the naitive tools of elastic search?

And second question

I have some not\_analyzed string fields, and I try to search by this  
fields on the 500 000 items on ES, and I have 2 second on my computer  
that is not realy fast  
What I need to do, to make it faster?

---

<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:** [May 24, 2011, 8:25pm UTC](https://discuss.elastic.co/t/relevation-on-wildcard-results-and-wildcard-speed/4469/2 "2011-05-24T20:25:45Z")

</div>

wildcard searches are going to be slow, especially when doing leading wildcards. You have several options:

1. Use text\_phrase\_prefix query (new in 0.16.1), where you can control the number of max\_expansions to reduce the time it takes to query.
2. Use ngrams to try and provide different type of suggestions. That will need to be done by creating an analyzer for that, and defining it in the mappings. And then do a simple text query (both index text and search text will be analyzed and "ngrammed").  
On Tuesday, May 24, 2011 at 9:32 PM, Michael wrote:

> Hi guys!  
> I want to do something like this.  
> When I search for example on field first\_name by wildcard "_A_" I want  
> to see my result sortable like this
> 
> Andrew  
> Frank  
> Michael  
> Brenda
> 
> Can I do this by the naitive tools of Elasticsearch?
> 
> And second question
> 
> I have some not\_analyzed string fields, and I try to search by this  
> fields on the 500 000 items on ES, and I have 2 second on my computer  
> that is not realy fast  
> What I need to do, to make it faster?

---

<div class="post-metadata">

**Author:** ![Andrew\_Degtiariov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_degtiariov/32/3223_2.png) [@Andrew\_Degtiariov](https://discuss.elastic.co/u/Andrew_Degtiariov)\
**Post date:** [May 27, 2011, 1:30pm UTC](https://discuss.elastic.co/t/relevation-on-wildcard-results-and-wildcard-speed/4469/3 "2011-05-27T13:30:12Z")

</div>

On Tue, May 24, 2011 at 11:25 PM, Shay Banon  
[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> wildcard searches are going to be slow, especially when doing leading  
> wildcards. You have several options:
> 
> 1. Use text\_phrase\_prefix query (new in 0.16.1), where you can control the  
> number of max\_expansions to reduce the time it takes to query.
> 2. Use ngrams to try and provide different type of suggestions. That will  
> need to be done by creating an analyzer for that, and defining it in the  
> mappings. And then do a simple text query (both index text and search text  
> will be analyzed and "ngrammed").

Does text\_phrase\_prefix query works on not analyzed fields? My tests show it  
work like prefix when field is not analyzed:

For example:  
The query {'query': {'text\_phrase\_prefix': {'fields.name': {'query': 'yuriy  
os' } } } matched document with `fields.name` 'yuriy ostapyuk'

But the query {'query': {'text\_phrase\_prefix': {'fields.name': {'query':  
'os' } } } doesn't match any documents.

--  
Andrew Degtyarev  
DA-RIPE

---

<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:** [May 27, 2011, 1:32pm UTC](https://discuss.elastic.co/t/relevation-on-wildcard-results-and-wildcard-speed/4469/4 "2011-05-27T13:32:25Z")

</div>

Yes, it works on non analyzed fields, but then, the entire content is checked against as a single term. so you need to provide a full prefix. If you want the text to be "broken" down into more granular terms, then you need to have it analyzed.

On Friday, May 27, 2011 at 4:30 PM, Andrew Degtyarev wrote:

> On Tue, May 24, 2011 at 11:25 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> 
> > wildcard searches are going to be slow, especially when doing leading wildcards. You have several options:
> > 
> > 1. Use text\_phrase\_prefix query (new in 0.16.1), where you can control the number of max\_expansions to reduce the time it takes to query.
> > 2. Use ngrams to try and provide different type of suggestions. That will need to be done by creating an analyzer for that, and defining it in the mappings. And then do a simple text query (both index text and search text will be analyzed and "ngrammed").
> 
> Does text\_phrase\_prefix query works on not analyzed fields? My tests show it work like prefix when field is not analyzed:
> 
> For example:  
> The query {'query': {'text\_phrase\_prefix': {'fields.name ([http://fields.name](http://fields.name))': {'query': 'yuriy os' } } } matched document with `fields.name (http://fields.name)` 'yuriy ostapyuk'
> 
> But the query {'query': {'text\_phrase\_prefix': {'fields.name ([http://fields.name](http://fields.name))': {'query': 'os' } } } doesn't match any documents.
> 
> --  
> Andrew Degtyarev  
> DA-RIPE

---

<div class="post-metadata">

**Author:** ![Andrew\_Degtiariov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_degtiariov/32/3223_2.png) [@Andrew\_Degtiariov](https://discuss.elastic.co/u/Andrew_Degtiariov)\
**Post date:** [May 27, 2011, 2:20pm UTC](https://discuss.elastic.co/t/relevation-on-wildcard-results-and-wildcard-speed/4469/5 "2011-05-27T14:20:55Z")

</div>

On Fri, May 27, 2011 at 4:32 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Yes, it works on non analyzed fields, but then, the entire content is  
> checked against as a single term. so you need to provide a full prefix. If  
> you want the text to be "broken" down into more granular terms, then you  
> need to have it analyzed.

Hm...  
Don't understand. Could you explain about "full prefix"?

On Friday, May 27, 2011 at 4:30 PM, Andrew Degtyarev wrote:

> On Tue, May 24, 2011 at 11:25 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)
> 
> > wrote:
> 
> wildcard searches are going to be slow, especially when doing leading  
> wildcards. You have several options:
> 
> 1. Use text\_phrase\_prefix query (new in 0.16.1), where you can control the  
> number of max\_expansions to reduce the time it takes to query.
> 2. Use ngrams to try and provide different type of suggestions. That will  
> need to be done by creating an analyzer for that, and defining it in the  
> mappings. And then do a simple text query (both index text and search text  
> will be analyzed and "ngrammed").
> 
> Does text\_phrase\_prefix query works on not analyzed fields? My tests show  
> it work like prefix when field is not analyzed:
> 
> For example:  
> The query {'query': {'text\_phrase\_prefix': {'fields.name': {'query':  
> 'yuriy os' } } } matched document with `fields.name` 'yuriy ostapyuk'
> 
> But the query {'query': {'text\_phrase\_prefix': {'fields.name': {'query':  
> 'os' } } } doesn't match any documents.
> 
> --  
> Andrew Degtyarev  
> DA-RIPE

--  
Andrew Degtyarev  
DA-RIPE

---

<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:** [May 28, 2011, 9:33am UTC](https://discuss.elastic.co/t/relevation-on-wildcard-results-and-wildcard-speed/4469/6 "2011-05-28T09:33:50Z")

</div>

Since the entire content of the field is a single token (not indexed), then a prefix will only work on all of it. Exactly the behavior you saw.

On Friday, May 27, 2011 at 5:20 PM, Andrew Degtyarev wrote:

> On Fri, May 27, 2011 at 4:32 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> 
> > Yes, it works on non analyzed fields, but then, the entire content is checked against as a single term. so you need to provide a full prefix. If you want the text to be "broken" down into more granular terms, then you need to have it analyzed.
> 
> Hm...  
> Don't understand. Could you explain about "full prefix"?
> 
> > On Friday, May 27, 2011 at 4:30 PM, Andrew Degtyarev wrote:
> > 
> > > On Tue, May 24, 2011 at 11:25 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) ([mailto:shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com))\> wrote:
> > > 
> > > > wildcard searches are going to be slow, especially when doing leading wildcards. You have several options:
> > > > 
> > > > 1. Use text\_phrase\_prefix query (new in 0.16.1), where you can control the number of max\_expansions to reduce the time it takes to query.
> > > > 2. Use ngrams to try and provide different type of suggestions. That will need to be done by creating an analyzer for that, and defining it in the mappings. And then do a simple text query (both index text and search text will be analyzed and "ngrammed").
> > > 
> > > Does text\_phrase\_prefix query works on not analyzed fields? My tests show it work like prefix when field is not analyzed:
> > > 
> > > For example:  
> > > The query {'query': {'text\_phrase\_prefix': {'fields.name ([http://fields.name](http://fields.name))': {'query': 'yuriy os' } } } matched document with `fields.name (http://fields.name)` 'yuriy ostapyuk'
> > > 
> > > But the query {'query': {'text\_phrase\_prefix': {'fields.name ([http://fields.name](http://fields.name))': {'query': 'os' } } } doesn't match any documents.
> > > 
> > > --  
> > > Andrew Degtyarev  
> > > DA-RIPE
> 
> --  
> Andrew Degtyarev  
> DA-RIPE

---

<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, 4:05am UTC](https://discuss.elastic.co/t/relevation-on-wildcard-results-and-wildcard-speed/4469/7 "2017-07-06T04:05:10Z")

</div>


