# Synonym behavior with highlighting and multiple terms

**URL:** <https://discuss.elastic.co/t/synonym-behavior-with-highlighting-and-multiple-terms/5695>\
**Category:** Elasticsearch\
**Created:** [October 26, 2011, 6:48pm UTC](https://discuss.elastic.co/t/synonym-behavior-with-highlighting-and-multiple-terms/5695 "2011-10-26T18:48:07Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [October 26, 2011, 6:48pm UTC](https://discuss.elastic.co/t/synonym-behavior-with-highlighting-and-multiple-terms/5695/1 "2011-10-26T18:48:07Z")

</div>

Hey,  
I'm seeing a couple of issues that I have pointed out in this gist:

> <https://gist.github.com/ppearcy/1317149>

The first issue that appears to be a bug is that highlighting can be  
incorrect in the case of multi-term synonyms. The returned data for  
the 2nd result is:  
atripla

I reproduced this with term\_vectors no and with\_positions\_offsets, so  
appears to affect both highlighting paths.

Next, it appears that synonym expansion occurs to the query string,  
which gives some unexpected results, as all the terms in the synonym  
list are injected into the query. So, looking at the 2nd result again,  
atripla is returned because it is a synonym with "efavirenz  
emtricitabine" and truvada is a synonym with "emtricitabine  
tenofovir", which doesn't seem to be the correct behavior. I  
understand why this is occurring, the synonym term expansion is  
occurring both index side and query side, but that doesn't seem right.  
When I specify to use an analyzer without the synonym filter, this  
goes away.

I am going to play around more with expand=false and see if the  
behavior is any better.

Thanks,  
Paul

---

<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:** [October 26, 2011, 8:45pm UTC](https://discuss.elastic.co/t/synonym-behavior-with-highlighting-and-multiple-terms/5695/2 "2011-10-26T20:45:10Z")

</div>

I will have a look at it and try and see where the problem is. Just a quick  
note, you can configure a different index and search analyzer on a field (or  
explicitly an analyzer when you search).

On Wed, Oct 26, 2011 at 8:48 PM, ppearcy [ppearcy@gmail.com](mailto:ppearcy@gmail.com) wrote:

> Hey,  
> I'm seeing a couple of issues that I have pointed out in this gist:  
> [1317149’s gists · GitHub](https://gist.github.com/1317149)
> 
> The first issue that appears to be a bug is that highlighting can be  
> incorrect in the case of multi-term synonyms. The returned data for  
> the 2nd result is:  
> atripla
> 
> I reproduced this with term\_vectors no and with\_positions\_offsets, so  
> appears to affect both highlighting paths.
> 
> Next, it appears that synonym expansion occurs to the query string,  
> which gives some unexpected results, as all the terms in the synonym  
> list are injected into the query. So, looking at the 2nd result again,  
> atripla is returned because it is a synonym with "efavirenz  
> emtricitabine" and truvada is a synonym with "emtricitabine  
> tenofovir", which doesn't seem to be the correct behavior. I  
> understand why this is occurring, the synonym term expansion is  
> occurring both index side and query side, but that doesn't seem right.  
> When I specify to use an analyzer without the synonym filter, this  
> goes away.
> 
> I am going to play around more with expand=false and see if the  
> behavior is any better.
> 
> Thanks,  
> Paul

---

<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:** [November 7, 2011, 7:13pm UTC](https://discuss.elastic.co/t/synonym-behavior-with-highlighting-and-multiple-terms/5695/3 "2011-11-07T19:13:00Z")

</div>

FYI, setting the search analyzer not to have the synonym filter and  
only having this applied index time, does help with the poor search  
results due to the search time synonym expansion.

However, the highlighting issue is still present. I opened a ticket to  
track:

> <https://github.com/elastic/elasticsearch/issues/1444>
>
> It appears that when using a synonym filter and there are multi-term synonyms, h…ighlighting doesn't always work correctly.
> 
> Details how to reproduce are here:
> https://gist.github.com/1317149

I hope to find some time to debug this and will update the ticket with  
any details I find out.

Thanks,  
Paul

On Oct 26, 1:45 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> I will have a look at it and try and see where the problem is. Just a quick  
> note, you can configure a different index and search analyzer on a field (or  
> explicitly an analyzer when you search).
> 
> On Wed, Oct 26, 2011 at 8:48 PM, ppearcy [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:
> 
> > Hey,  
> > I'm seeing a couple of issues that I have pointed out in this gist:  
> > [1317149’s gists · GitHub](https://gist.github.com/1317149)
> 
> > The first issue that appears to be a bug is that highlighting can be  
> > incorrect in the case of multi-term synonyms. The returned data for  
> > the 2nd result is:  
> > atripla
> 
> > I reproduced this with term\_vectors no and with\_positions\_offsets, so  
> > appears to affect both highlighting paths.
> 
> > Next, it appears that synonym expansion occurs to the query string,  
> > which gives some unexpected results, as all the terms in the synonym  
> > list are injected into the query. So, looking at the 2nd result again,  
> > atripla is returned because it is a synonym with "efavirenz  
> > emtricitabine" and truvada is a synonym with "emtricitabine  
> > tenofovir", which doesn't seem to be the correct behavior. I  
> > understand why this is occurring, the synonym term expansion is  
> > occurring both index side and query side, but that doesn't seem right.  
> > When I specify to use an analyzer without the synonym filter, this  
> > goes away.
> 
> > I am going to play around more with expand=false and see if the  
> > behavior is any better.
> 
> > Thanks,  
> > Paul

---

<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:** [November 9, 2011, 12:00am UTC](https://discuss.elastic.co/t/synonym-behavior-with-highlighting-and-multiple-terms/5695/4 "2011-11-09T00:00:51Z")

</div>

FYI, now hitting a case where the search is actually failing. My guess  
is that this and the other issue I mentioned in this thread are  
related. To reproduce:

> <https://gist.github.com/ppearcy/1349777>

On Nov 7, 12:13 pm, ppearcy [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:

> FYI, setting the search analyzer not to have thesynonymfilter and  
> only having this applied index time, does help with the poor search  
> results due to the search timesynonymexpansion.
> 
> However, the highlighting issue is still present. I opened a ticket to  
> track:[Multi-term synonyms not highlighting correctly · Issue #1444 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1444)
> 
> I hope to find some time to debug this and will update the ticket with  
> any details I find out.
> 
> Thanks,  
> Paul
> 
> On Oct 26, 1:45 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > I will have a look at it and try and see where the problem is. Just a quick  
> > note, you can configure a different index and search analyzer on a field (or  
> > explicitly an analyzer when you search).
> 
> > On Wed, Oct 26, 2011 at 8:48 PM, ppearcy [ppea...@gmail.com](mailto:ppea...@gmail.com) wrote:
> > 
> > > Hey,  
> > > I'm seeing a couple of issues that I have pointed out in this gist:  
> > > [1317149’s gists · GitHub](https://gist.github.com/1317149)
> 
> > > The first issue that appears to be a bug is that highlighting can be  
> > > incorrect in the case of multi-term synonyms. The returned data for  
> > > the 2nd result is:  
> > > atripla
> 
> > > I reproduced this with term\_vectors no and with\_positions\_offsets, so  
> > > appears to affect both highlighting paths.
> 
> > > Next, it appears thatsynonymexpansion occurs to the query string,  
> > > which gives some unexpected results, as all the terms in thesynonym  
> > > list are injected into the query. So, looking at the 2nd result again,  
> > > atripla is returned because it is asynonymwith "efavirenz  
> > > emtricitabine" and truvada is asynonymwith "emtricitabine  
> > > tenofovir", which doesn't seem to be the correct behavior. I  
> > > understand why this is occurring, thesynonymterm expansion is  
> > > occurring both index side and query side, but that doesn't seem right.  
> > > When I specify to use an analyzer without thesynonymfilter, this  
> > > goes away.
> 
> > > I am going to play around more with expand=false and see if the  
> > > behavior is any better.
> 
> > > Thanks,  
> > > Paul

---

<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:49am UTC](https://discuss.elastic.co/t/synonym-behavior-with-highlighting-and-multiple-terms/5695/5 "2017-07-06T03:49:28Z")

</div>


