# Multiple synonyms contribute to the score

**URL:** <https://discuss.elastic.co/t/multiple-synonyms-contribute-to-the-score/9744>\
**Category:** Elasticsearch\
**Created:** [November 16, 2012, 7:22pm UTC](https://discuss.elastic.co/t/multiple-synonyms-contribute-to-the-score/9744 "2012-11-16T19:22:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Lawrence](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_lawrence/32/1951_2.png) [@Kevin\_Lawrence](https://discuss.elastic.co/u/Kevin_Lawrence)\
**Post date:** [November 16, 2012, 7:22pm UTC](https://discuss.elastic.co/t/multiple-synonyms-contribute-to-the-score/9744/1 "2012-11-16T19:22:14Z")

</div>

I have a synonym file that includes the row:

sunitinib,su11248,su011248,sutent

When I search for 'sutent' and look at the \_explain results, I see that  
each hit contributes to the score, even though the source document only has  
one mention of 'sutent' and none of its synonyms. The net result is that  
words with more synonyms artificially get a boost in the results.

- 
  - 0.8291347 = weight(brief\_title:sunitinib in 27490), product of:

- 
  - 0.8291347 = weight(brief\_title:sunitinib in 27490), product of:

- 
  - 0.5862867 = weight(brief\_title:su11248 in 27490), product of:

- 
  - 0.5862867 = weight(brief\_title:su011248 in 27490), product of:

- 
  - 0.5862867 = weight(brief\_title:sutent in 27490), product of:

Trying expand=true and expand=false in the mapping makes no difference. Is  
there a setting I can change to avoid this behaviour?

I'll put together a gist if the solution is not immediately obvious to  
someone.

Thanks in advance,

Kevin

BONUS QUESTION: is there an explanation somewhere of when I should  
expand=false? I read the explanation in the doc but I'm still not getting  
it.

--

---

<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:** [November 17, 2012, 12:14pm UTC](https://discuss.elastic.co/t/multiple-synonyms-contribute-to-the-score/9744/2 "2012-11-17T12:14:41Z")

</div>

Hi Kevin

> When I search for 'sutent' and look at the \_explain results, I see  
> that each hit contributes to the score, even though the source  
> document only has one mention of 'sutent' and none of its synonyms.  
> The net result is that words with more synonyms artificially get a  
> boost in the results.

There are various ways to approach this problem. Either you:

```
  * expand your synonym list at index time (ie you store all
    variations of the synonym in your index), but then you search on
    just one variation (by using a different analyzer at search or
    index time),
  * contract your synonym list at index and search time: eg foo, bar
    or baz all get indexed as just 'foo'. A search for 'bar'
    becomes a search for 'foo'

```

I have put together a gist demonstrating how this all works:

> <https://gist.github.com/clintongormley/4095280>

The question remains: which should I prefer? expand: true or false?

I'm open to disagreement, but my vote would be for expand: false. ie  
index just the first word in the synonym list, not all the words.

My reason for that is:

1. fewer terms to index

2. replacing synonyms with all variations or just one variation  
implies the same loss of original information (ie which synonym  
appeared in the original text).

3. Synonyms can be of different lengths (eg "wi fi" vs "wifi"), which  
means that (with expand: true), the phrase "wifi router" would be  
indexed as:

hth

clint

--

---

<div class="post-metadata">

**Author:** ![Kevin\_Lawrence](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_lawrence/32/1951_2.png) [@Kevin\_Lawrence](https://discuss.elastic.co/u/Kevin_Lawrence)\
**Post date:** [November 19, 2012, 10:07pm UTC](https://discuss.elastic.co/t/multiple-synonyms-contribute-to-the-score/9744/3 "2012-11-19T22:07:27Z")

</div>

Thank you Clint, that helps my understanding a lot. I will try expand=false.

And thanks for the gist, too.

Kevin

On Saturday, November 17, 2012 4:14:50 AM UTC-8, Clinton Gormley wrote:

> There are various ways to approach this problem. Either you:
> 
> ```
> * expand your synonym list at index time (ie you store all 
> variations of the synonym in your index), but then you search on 
> just one variation (by using a different analyzer at search or 
> index time), 
> * contract your synonym list at index and search time: eg foo, bar 
> or baz all get indexed as just 'foo'. A search for 'bar' 
> becomes a search for 'foo' 
> 
> ```
> 
> I have put together a gist demonstrating how this all works:  
> [Using synonyms in Elasticsearch · GitHub](https://gist.github.com/4095280)

--

---

<div class="post-metadata">

**Author:** ![Kevin\_Lawrence](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_lawrence/32/1951_2.png) [@Kevin\_Lawrence](https://discuss.elastic.co/u/Kevin_Lawrence)\
**Post date:** [November 20, 2012, 12:54am UTC](https://discuss.elastic.co/t/multiple-synonyms-contribute-to-the-score/9744/4 "2012-11-20T00:54:28Z")

</div>

A quick note to confirm that this worked for me and to thank you for an  
amazingly detailed answer. I learned a ton of stuff from reading your gist.

Thank you, Clint!

Kevin

On Saturday, November 17, 2012 4:14:50 AM UTC-8, Clinton Gormley wrote:

> > ```
> > * contract your synonym list at index and search time: eg foo, bar 
> > or baz all get indexed as just 'foo'. A search for 'bar' 
> > becomes a search for 'foo' 
> > 
> > ```
> > 
> > I have put together a gist demonstrating how this all works:  
> > [Using synonyms in Elasticsearch · GitHub](https://gist.github.com/4095280)

--

---

<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:** [November 20, 2012, 10:23am UTC](https://discuss.elastic.co/t/multiple-synonyms-contribute-to-the-score/9744/5 "2012-11-20T10:23:00Z")

</div>

On Mon, 2012-11-19 at 16:54 -0800, Kevin Lawrence wrote:

> A quick note to confirm that this worked for me and to thank you for  
> an amazingly detailed answer. I learned a ton of stuff from reading  
> your gist.

glad it helped 🙂

> Thank you, Clint!
> 
> Kevin
> 
> ```
> On Saturday, November 17, 2012 4:14:50 AM UTC-8, Clinton
> Gormley wrote:
> * contract your synonym list at index and search
> time: eg foo, bar 
> or baz all get indexed as just 'foo'. A
> search for 'bar' 
> becomes a search for 'foo' 
>             
> I have put together a gist demonstrating how this all
> works: 
> https://gist.github.com/4095280 
> 
> ```
> 
> --

--

---

<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:03am UTC](https://discuss.elastic.co/t/multiple-synonyms-contribute-to-the-score/9744/6 "2017-07-06T03:03:36Z")

</div>


