# \[Theory\] Improving search result relevance?

**URL:** <https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855>\
**Category:** Elasticsearch\
**Created:** [November 28, 2012, 3:51am UTC](https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855 "2012-11-28T03:51:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [November 28, 2012, 3:51am UTC](https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855/1 "2012-11-28T03:51:56Z")

</div>

I'm curious about some practical tips to improve search result relevance.  
Currently, I'm tokenizing my fields with shingles and performing a simple  
"text" search on the shingled field. I've found this gives better results  
than other things I've tried (combinations of: terms, n-grams, phrase,  
shingles). However, search results leave something to be desired. I  
imagine there are ways to fix this...I just don't know how.

For example, if I search for "Servo Gear", it will match all documents with  
either "Servo" or "Gear" and order them roughly based on frequency. There  
is some preference to documents that say "Servo Gear" explicitly, but often  
a document that lists "Gear" four times will rank higher simply because it  
has the term more frequently. Ideally, something that matches the phrase  
would rank higher.

So, how should I attack this problem? I'm thinking something like this:

- Analyzers
  - Regular term tokenizer
  - Shingles, but turn off unigrams

- Search both terms and shingles, but boost shingles so that phrase  
matches are sorted higher
- Perhaps search using span\_near so that non-exact phrases can be  
matched too? Would it be better to do something like a phrase query with  
slop instead?

Does that make sense? I understand ES well enough from a technical point  
of view, but I'm having a hard time implementing more subtle search  
algorithms that can surface the correct documents.

Thanks!  
-Zach

--

---

<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:** [January 28, 2013, 4:17am UTC](https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855/2 "2013-01-28T04:17:31Z")

</div>

Hi, all. I'm having a little bit different problem, but I guess in essence  
it's the same.

I have an index with items and trying to search by title 'iphone 5'.  
I can get well sorted items 'iphone 5' and then all other 'iphone 3g',  
'iphone 4s', etc.

Now my problem is that there's also 'Loreal Elseve 5' in search results,  
i.e. elastic including in search results all entries with number 5 (and the  
score is pretty high). How could I solve it?

I don't want to filter out all numbers at indexing phase, because they're very  
useful in such a case when I search for keyword followed by number or  
version.

On Wednesday, November 28, 2012 9:51:56 AM UTC+6, Zachary Tong wrote:

> I'm curious about some practical tips to improve search result relevance.  
> Currently, I'm tokenizing my fields with shingles and performing a simple  
> "text" search on the shingled field. I've found this gives better results  
> than other things I've tried (combinations of: terms, n-grams, phrase,  
> shingles). However, search results leave something to be desired. I  
> imagine there are ways to fix this...I just don't know how.
> 
> For example, if I search for "Servo Gear", it will match all documents  
> with either "Servo" or "Gear" and order them roughly based on frequency.  
> There is some preference to documents that say "Servo Gear" explicitly,  
> but often a document that lists "Gear" four times will rank higher simply  
> because it has the term more frequently. Ideally, something that matches  
> the phrase would rank higher.
> 
> So, how should I attack this problem? I'm thinking something like this:
> 
> - Analyzers
> - Regular term tokenizer
> - Shingles, but turn off unigrams
> 
> - Search both terms and shingles, but boost shingles so that phrase  
> matches are sorted higher
> - Perhaps search using span\_near so that non-exact phrases can be  
> matched too? Would it be better to do something like a phrase query with  
> slop instead?
> 
> Does that make sense? I understand ES well enough from a technical point  
> of view, but I'm having a hard time implementing more subtle search  
> algorithms that can surface the correct documents.
> 
> Thanks!  
> -Zach

--

---

<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:** [January 28, 2013, 3:58pm UTC](https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855/3 "2013-01-28T15:58:27Z")

</div>

On Sun, 2013-01-27 at 20:17 -0800, Rauan Maemirov wrote:

> Hi, all. I'm having a little bit different problem, but I guess in  
> essence it's the same.
> 
> I have an index with items and trying to search by title 'iphone 5'.  
> I can get well sorted items 'iphone 5' and then all other 'iphone 3g',  
> 'iphone 4s', etc.
> 
> Now my problem is that there's also 'Loreal Elseve 5' in search  
> results, i.e. elastic including in search results all entries with  
> number 5 (and the score is pretty high). How could I solve it?

You could try setting minimum\_should\_match to eg "60%"

clint

> I don't want to filter out all numbers at indexing phase, because  
> they're very useful in such a case when I search for keyword followed  
> by number or version.
> 
> On Wednesday, November 28, 2012 9:51:56 AM UTC+6, Zachary Tong wrote:  
> I'm curious about some practical tips to improve search result  
> relevance. Currently, I'm tokenizing my fields with shingles  
> and performing a simple "text" search on the shingled field.  
> I've found this gives better results than other things I've  
> tried (combinations of: terms, n-grams, phrase, shingles).  
> However, search results leave something to be desired. I  
> imagine there are ways to fix this...I just don't know how.
> 
> ```
> For example, if I search for "Servo Gear", it will match all
> documents with either "Servo" or "Gear" and order them roughly
> based on frequency. There is some preference to documents
> that say "Servo Gear" explicitly, but often a document that
> lists "Gear" four times will rank higher simply because it has
> the term more frequently. Ideally, something that matches the
> phrase would rank higher.
>     
>     
> So, how should I attack this problem? I'm thinking something
> like this:
> * Analyzers
> * Regular term tokenizer
> * Shingles, but turn off unigrams
> * Search both terms and shingles, but boost shingles so
> that phrase matches are sorted higher
> * Perhaps search using span_near so that non-exact
> phrases can be matched too? Would it be better to do
> something like a phrase query with slop instead?
> Does that make sense? I understand ES well enough from a
> technical point of view, but I'm having a hard time
> implementing more subtle search algorithms that can surface
> the correct documents.
>     
>     
> Thanks!
> -Zach
> 
> ```
> 
> --

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [January 28, 2013, 8:29pm UTC](https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855/4 "2013-01-28T20:29:00Z")

</div>

Specifically regarding exact phrases getting ranked higher, I like using a  
phrase boost technique and use a term based analyzer. This breaks down like:  
(field:"test search")^PhraseBoostValue OR field:(test search)

Best Regards,  
Paul

On Monday, January 28, 2013 8:58:27 AM UTC-7, Clinton Gormley wrote:

> On Sun, 2013-01-27 at 20:17 -0800, Rauan Maemirov wrote:
> 
> > Hi, all. I'm having a little bit different problem, but I guess in  
> > essence it's the same.
> > 
> > I have an index with items and trying to search by title 'iphone 5'.  
> > I can get well sorted items 'iphone 5' and then all other 'iphone 3g',  
> > 'iphone 4s', etc.
> > 
> > Now my problem is that there's also 'Loreal Elseve 5' in search  
> > results, i.e. elastic including in search results all entries with  
> > number 5 (and the score is pretty high). How could I solve it?
> 
> You could try setting minimum\_should\_match to eg "60%"
> 
> clint
> 
> > I don't want to filter out all numbers at indexing phase, because  
> > they're very useful in such a case when I search for keyword followed  
> > by number or version.
> > 
> > On Wednesday, November 28, 2012 9:51:56 AM UTC+6, Zachary Tong wrote:  
> > I'm curious about some practical tips to improve search result  
> > relevance. Currently, I'm tokenizing my fields with shingles  
> > and performing a simple "text" search on the shingled field.  
> > I've found this gives better results than other things I've  
> > tried (combinations of: terms, n-grams, phrase, shingles).  
> > However, search results leave something to be desired. I  
> > imagine there are ways to fix this...I just don't know how.
> > 
> > ```
> > For example, if I search for "Servo Gear", it will match all 
> > documents with either "Servo" or "Gear" and order them roughly 
> > based on frequency. There is some preference to documents 
> > that say "Servo Gear" explicitly, but often a document that 
> > lists "Gear" four times will rank higher simply because it has 
> > the term more frequently. Ideally, something that matches the 
> > phrase would rank higher. 
> >     
> >     
> > So, how should I attack this problem? I'm thinking something 
> > like this: 
> > * Analyzers 
> > * Regular term tokenizer 
> > * Shingles, but turn off unigrams 
> > * Search both terms and shingles, but boost shingles so 
> > that phrase matches are sorted higher 
> > * Perhaps search using span_near so that non-exact 
> > phrases can be matched too? Would it be better to do 
> > something like a phrase query with slop instead? 
> > Does that make sense? I understand ES well enough from a 
> > technical point of view, but I'm having a hard time 
> > implementing more subtle search algorithms that can surface 
> > the correct documents. 
> >     
> >     
> > Thanks! 
> > -Zach 
> > 
> > ```
> > 
> > --

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [January 29, 2013, 4:19am UTC](https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855/5 "2013-01-29T04:19:33Z")

</div>

Hi, Clinton.

I tried, but i still keep getting any occurences of 5.

Anu other suggestions? I already use query\_string fields boosting like "fields":  
["title^2", "tags^2", "description"]

On Monday, January 28, 2013 9:58:27 PM UTC+6, Clinton Gormley wrote:

> On Sun, 2013-01-27 at 20:17 -0800, Rauan Maemirov wrote:
> 
> > Hi, all. I'm having a little bit different problem, but I guess in  
> > essence it's the same.
> > 
> > I have an index with items and trying to search by title 'iphone 5'.  
> > I can get well sorted items 'iphone 5' and then all other 'iphone 3g',  
> > 'iphone 4s', etc.
> > 
> > Now my problem is that there's also 'Loreal Elseve 5' in search  
> > results, i.e. elastic including in search results all entries with  
> > number 5 (and the score is pretty high). How could I solve it?
> 
> You could try setting minimum\_should\_match to eg "60%"
> 
> clint
> 
> > I don't want to filter out all numbers at indexing phase, because  
> > they're very useful in such a case when I search for keyword followed  
> > by number or version.
> > 
> > On Wednesday, November 28, 2012 9:51:56 AM UTC+6, Zachary Tong wrote:  
> > I'm curious about some practical tips to improve search result  
> > relevance. Currently, I'm tokenizing my fields with shingles  
> > and performing a simple "text" search on the shingled field.  
> > I've found this gives better results than other things I've  
> > tried (combinations of: terms, n-grams, phrase, shingles).  
> > However, search results leave something to be desired. I  
> > imagine there are ways to fix this...I just don't know how.
> > 
> > ```
> > For example, if I search for "Servo Gear", it will match all 
> > documents with either "Servo" or "Gear" and order them roughly 
> > based on frequency. There is some preference to documents 
> > that say "Servo Gear" explicitly, but often a document that 
> > lists "Gear" four times will rank higher simply because it has 
> > the term more frequently. Ideally, something that matches the 
> > phrase would rank higher. 
> >     
> >     
> > So, how should I attack this problem? I'm thinking something 
> > like this: 
> > * Analyzers 
> > * Regular term tokenizer 
> > * Shingles, but turn off unigrams 
> > * Search both terms and shingles, but boost shingles so 
> > that phrase matches are sorted higher 
> > * Perhaps search using span_near so that non-exact 
> > phrases can be matched too? Would it be better to do 
> > something like a phrase query with slop instead? 
> > Does that make sense? I understand ES well enough from a 
> > technical point of view, but I'm having a hard time 
> > implementing more subtle search algorithms that can surface 
> > the correct documents. 
> >     
> >     
> > Thanks! 
> > -Zach 
> > 
> > ```
> > 
> > --

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [January 29, 2013, 7:17am UTC](https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855/6 "2013-01-29T07:17:46Z")

</div>

Hey,

On Wednesday, November 28, 2012 4:51:56 AM UTC+1, Zachary Tong wrote:

> I'm curious about some practical tips to improve search result relevance.  
> Currently, I'm tokenizing my fields with shingles and performing a simple  
> "text" search on the shingled field. I've found this gives better results  
> than other things I've tried (combinations of: terms, n-grams, phrase,  
> shingles). However, search results leave something to be desired. I  
> imagine there are ways to fix this...I just don't know how.

For example, if I search for "Servo Gear", it will match all documents with

> either "Servo" or "Gear" and order them roughly based on frequency. There  
> is some preference to documents that say "Servo Gear" explicitly, but often  
> a document that lists "Gear" four times will rank higher simply because it  
> has the term more frequently. Ideally, something that matches the phrase  
> would rank higher.
> 
> So, how should I attack this problem? I'm thinking something like this:
> 
> - Analyzers
> - Regular term tokenizer
> - Shingles, but turn off unigrams
> 
> - Search both terms and shingles, but boost shingles so that phrase  
> matches are sorted higher
> - Perhaps search using span\_near so that non-exact phrases can be  
> matched too? Would it be better to do something like a phrase query with  
> slop instead?
> 
> Does that make sense? I understand ES well enough from a technical point  
> of view, but I'm having a hard time implementing more subtle search  
> algorithms that can surface the correct documents.

Shingles are a good start here. I would personally index the shingles in a  
dedicated field without unigrams and have a secondary field that doesn't  
use shingles. That way you can boost the shingle field according to your  
needs. I would also think about using a  
DijunctionMaxQuery as the top-level query and for each sub query (one on  
the shingle field and one on the unigram field) you use the  
minimum\_should\_match syntax to donate when the query should produce a match.

simon

> Thanks!  
> -Zach

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Alan\_Woodward](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@Alan\_Woodward](https://discuss.elastic.co/u/Alan_Woodward)\
**Post date:** [January 29, 2013, 9:21am UTC](https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855/7 "2013-01-29T09:21:34Z")

</div>

We implemented this sort of phrase-boosting for a client recently by shingling the query string outside elasticsearch and then adding the shingles as phrase queries in SHOULD clauses. So a search for 'annual leave entitlement' became:

"bool" : { "must" : { "query\_string" : "annual leave entitlement" },  
"should" : [ { "text" : { "type" : "phrase", "query" : "annual leave" } },  
{ "text" : "type" : "phrase", "query" : "leave entitlement" }} ] }

Alan Woodward

> **[Search Consultants | Big Data | Tuning | Lucene/Solr | Elasticsearch | Flax](https://www.flax.co.uk/)**
>
> Flax search consultants provide consulting services for open source search engines including Lucene / Solr & Elasticsearch, Hadoop, Kafka, Samza, Logstash, Kibana. We also offer relevancy tuning, media monitoring and big data analysis. Get in...

On 29 Jan 2013, at 07:17, simonw wrote:

> Hey,
> 
> On Wednesday, November 28, 2012 4:51:56 AM UTC+1, Zachary Tong wrote:  
> I'm curious about some practical tips to improve search result relevance. Currently, I'm tokenizing my fields with shingles and performing a simple "text" search on the shingled field. I've found this gives better results than other things I've tried (combinations of: terms, n-grams, phrase, shingles). However, search results leave something to be desired. I imagine there are ways to fix this...I just don't know how.
> 
> For example, if I search for "Servo Gear", it will match all documents with either "Servo" or "Gear" and order them roughly based on frequency. There is some preference to documents that say "Servo Gear" explicitly, but often a document that lists "Gear" four times will rank higher simply because it has the term more frequently. Ideally, something that matches the phrase would rank higher.
> 
> So, how should I attack this problem? I'm thinking something like this:  
> Analyzers  
> Regular term tokenizer  
> Shingles, but turn off unigrams  
> Search both terms and shingles, but boost shingles so that phrase matches are sorted higher  
> Perhaps search using span\_near so that non-exact phrases can be matched too? Would it be better to do something like a phrase query with slop instead?  
> Does that make sense? I understand ES well enough from a technical point of view, but I'm having a hard time implementing more subtle search algorithms that can surface the correct documents.
> 
> Shingles are a good start here. I would personally index the shingles in a dedicated field without unigrams and have a secondary field that doesn't use shingles. That way you can boost the shingle field according to your needs. I would also think about using a  
> DijunctionMaxQuery as the top-level query and for each sub query (one on the shingle field and one on the unigram field) you use the minimum\_should\_match syntax to donate when the query should produce a match.
> 
> simon
> 
> Thanks!  
> -Zach
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [February 12, 2013, 8:28am UTC](https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855/8 "2013-02-12T08:28:33Z")

</div>

My question is still open.  
What is the most general solution to this?

I tried to query with use\_dis\_max, but it doen't change a lot.  
I would try to set threshold on score, but every single occurence of number  
5 in index have a score roughly the same as the most relevant results.

On Tuesday, January 29, 2013 10:19:33 AM UTC+6, Rauan Maemirov wrote:

> Hi, Clinton.
> 
> I tried, but i still keep getting any occurences of 5.
> 
> Anu other suggestions? I already use query\_string fields boosting like "fields":  
> ["title^2", "tags^2", "description"]
> 
> On Monday, January 28, 2013 9:58:27 PM UTC+6, Clinton Gormley wrote:
> 
> > On Sun, 2013-01-27 at 20:17 -0800, Rauan Maemirov wrote:
> > 
> > > Hi, all. I'm having a little bit different problem, but I guess in  
> > > essence it's the same.
> > > 
> > > I have an index with items and trying to search by title 'iphone 5'.  
> > > I can get well sorted items 'iphone 5' and then all other 'iphone 3g',  
> > > 'iphone 4s', etc.
> > > 
> > > Now my problem is that there's also 'Loreal Elseve 5' in search  
> > > results, i.e. elastic including in search results all entries with  
> > > number 5 (and the score is pretty high). How could I solve it?
> > 
> > You could try setting minimum\_should\_match to eg "60%"
> > 
> > clint
> > 
> > > I don't want to filter out all numbers at indexing phase, because  
> > > they're very useful in such a case when I search for keyword followed  
> > > by number or version.
> > > 
> > > On Wednesday, November 28, 2012 9:51:56 AM UTC+6, Zachary Tong wrote:  
> > > I'm curious about some practical tips to improve search result  
> > > relevance. Currently, I'm tokenizing my fields with shingles  
> > > and performing a simple "text" search on the shingled field.  
> > > I've found this gives better results than other things I've  
> > > tried (combinations of: terms, n-grams, phrase, shingles).  
> > > However, search results leave something to be desired. I  
> > > imagine there are ways to fix this...I just don't know how.
> > > 
> > > ```
> > > For example, if I search for "Servo Gear", it will match all 
> > > documents with either "Servo" or "Gear" and order them roughly 
> > > based on frequency. There is some preference to documents 
> > > that say "Servo Gear" explicitly, but often a document that 
> > > lists "Gear" four times will rank higher simply because it has 
> > > the term more frequently. Ideally, something that matches the 
> > > phrase would rank higher. 
> > >     
> > >     
> > > So, how should I attack this problem? I'm thinking something 
> > > like this: 
> > > * Analyzers 
> > > * Regular term tokenizer 
> > > * Shingles, but turn off unigrams 
> > > * Search both terms and shingles, but boost shingles so 
> > > that phrase matches are sorted higher 
> > > * Perhaps search using span_near so that non-exact 
> > > phrases can be matched too? Would it be better to do 
> > > something like a phrase query with slop instead? 
> > > Does that make sense? I understand ES well enough from a 
> > > technical point of view, but I'm having a hard time 
> > > implementing more subtle search algorithms that can surface 
> > > the correct documents. 
> > >     
> > >     
> > > Thanks! 
> > > -Zach 
> > > 
> > > ```
> > > 
> > > --

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:51am UTC](https://discuss.elastic.co/t/theory-improving-search-result-relevance/9855/9 "2017-07-06T02:51:56Z")

</div>


