# Optimizing prefix search

**URL:** <https://discuss.elastic.co/t/optimizing-prefix-search/21382>\
**Category:** Elasticsearch\
**Created:** [December 24, 2014, 9:39am UTC](https://discuss.elastic.co/t/optimizing-prefix-search/21382 "2014-12-24T09:39:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [December 24, 2014, 9:39am UTC](https://discuss.elastic.co/t/optimizing-prefix-search/21382/1 "2014-12-24T09:39:46Z")

</div>

Hey all. I've been following this guide and it's  
wonderful! [http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/proximity-relevance.html](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/proximity-relevance.html)  
But it doesn't work well for large indexes.

Here's what i'm trying to do:  
1). Find matches that will be both relevant and similar to the original  
form.

{  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"must": {  
"multi\_match": {  
"query": "first th",  
"minimum\_should\_match": "40%",  
"type": "most\_fields",  
"slop": 10,  
"fields": ["title", "title\_original"]  
}  
},  
"should": {  
"multi\_match": {  
"query": "first th",  
"type": "phrase\_prefix",  
"slop": 50,  
"fields": ["title", "title\_original"],  
"max\_expansions": 50  
}  
}  
}  
}  
}  
}  
}

2). I'm setting minimal score 1 to throw out long-tail.

When I search for let's say 'first thir' it works like a charm. But if I  
try searching for 'first th', there can be items with exact 'th' word in  
it, so relevance is broken and every result has very low score. What I need  
to do is to throw out items like 'th', 'third' etc, and boost score for  
items that contains both 'first' and words starting with 'th'. Matching  
exactly by whole title 'first th' wouldn't help because I might need items  
like 'first second third'. I tried playing with slop, but it doesn't solve  
the problem globally.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1d036247-e6d1-462e-86c8-50182956196d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1d036247-e6d1-462e-86c8-50182956196d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![BillyEm](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@BillyEm](https://discuss.elastic.co/u/BillyEm)\
**Post date:** [December 25, 2014, 4:05am UTC](https://discuss.elastic.co/t/optimizing-prefix-search/21382/2 "2014-12-25T04:05:17Z")

</div>

You're trying, I think, to do phrase search with edit-distance embedded.  
Certainly a doable task. btw and fwiw: relevance is hardly ever "broken".  
😉

On Wednesday, December 24, 2014 4:39:46 AM UTC-5, Rauan Maemirov wrote:

> Hey all. I've been following this guide and it's wonderful!  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/proximity-relevance.html)  
> But it doesn't work well for large indexes.
> 
> Here's what i'm trying to do:  
> 1). Find matches that will be both relevant and similar to the original  
> form.
> 
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "bool": {  
> "must": {  
> "multi\_match": {  
> "query": "first th",  
> "minimum\_should\_match": "40%",  
> "type": "most\_fields",  
> "slop": 10,  
> "fields": ["title", "title\_original"]  
> }  
> },  
> "should": {  
> "multi\_match": {  
> "query": "first th",  
> "type": "phrase\_prefix",  
> "slop": 50,  
> "fields": ["title", "title\_original"],  
> "max\_expansions": 50  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> 2). I'm setting minimal score 1 to throw out long-tail.
> 
> When I search for let's say 'first thir' it works like a charm. But if I  
> try searching for 'first th', there can be items with exact 'th' word in  
> it, so relevance is broken and every result has very low score. What I need  
> to do is to throw out items like 'th', 'third' etc, and boost score for  
> items that contains both 'first' and words starting with 'th'. Matching  
> exactly by whole title 'first th' wouldn't help because I might need items  
> like 'first second third'. I tried playing with slop, but it doesn't solve  
> the problem globally.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/042b5f25-514f-41b5-b2ef-cbf2778bc712%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/042b5f25-514f-41b5-b2ef-cbf2778bc712%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [December 25, 2014, 8:42am UTC](https://discuss.elastic.co/t/optimizing-prefix-search/21382/3 "2014-12-25T08:42:31Z")

</div>

Hey, Billy. Did you  
mean [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html)  
?  
Could you point me in the direction which parameters to look for?

On Thursday, December 25, 2014 10:05:17 AM UTC+6, BillyEm wrote:

> You're trying, I think, to do phrase search with edit-distance embedded.  
> Certainly a doable task. btw and fwiw: relevance is hardly ever "broken".  
> 😉
> 
> On Wednesday, December 24, 2014 4:39:46 AM UTC-5, Rauan Maemirov wrote:
> 
> > Hey all. I've been following this guide and it's wonderful!  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/proximity-relevance.html)  
> > But it doesn't work well for large indexes.
> > 
> > Here's what i'm trying to do:  
> > 1). Find matches that will be both relevant and similar to the original  
> > form.
> > 
> > {  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "bool": {  
> > "must": {  
> > "multi\_match": {  
> > "query": "first th",  
> > "minimum\_should\_match": "40%",  
> > "type": "most\_fields",  
> > "slop": 10,  
> > "fields": ["title", "title\_original"]  
> > }  
> > },  
> > "should": {  
> > "multi\_match": {  
> > "query": "first th",  
> > "type": "phrase\_prefix",  
> > "slop": 50,  
> > "fields": ["title", "title\_original"],  
> > "max\_expansions": 50  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > 2). I'm setting minimal score 1 to throw out long-tail.
> > 
> > When I search for let's say 'first thir' it works like a charm. But if I  
> > try searching for 'first th', there can be items with exact 'th' word in  
> > it, so relevance is broken and every result has very low score. What I need  
> > to do is to throw out items like 'th', 'third' etc, and boost score for  
> > items that contains both 'first' and words starting with 'th'. Matching  
> > exactly by whole title 'first th' wouldn't help because I might need items  
> > like 'first second third'. I tried playing with slop, but it doesn't solve  
> > the problem globally.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/707acbd7-06bc-446c-b0f6-31ee0806ef63%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/707acbd7-06bc-446c-b0f6-31ee0806ef63%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:41am UTC](https://discuss.elastic.co/t/optimizing-prefix-search/21382/4 "2017-07-06T00:41:59Z")

</div>

Closed on July 6, 2017, 12:41am UTC


