# Synonym search not working with abbreviations

**URL:** <https://discuss.elastic.co/t/synonym-search-not-working-with-abbreviations/211285>\
**Category:** Elasticsearch\
**Created:** [December 10, 2019, 11:18am UTC](https://discuss.elastic.co/t/synonym-search-not-working-with-abbreviations/211285 "2019-12-10T11:18:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandeepv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandeepv/32/59111_2.png) [@sandeepv](https://discuss.elastic.co/u/sandeepv)\
**Post date:** [December 10, 2019, 11:18am UTC](https://discuss.elastic.co/t/synonym-search-not-working-with-abbreviations/211285/1 "2019-12-10T11:18:57Z")

</div>

I am trying to implement synonyms in Elasticsearch below are my settings

```
PUT /my_index
{
  "settings": {
    "index": {
      "analysis": {
        "filter": {
          "synonym_filter": {
            "type": "synonym",
            "synonyms": [             
              "erp , ERP, enterprise resource planing",
              "eps , EPS, earnings per share"
            ]
          }
        },
        "analyzer": {
          "synonym_analyzer": {
            "tokenizer": "standard",
            "filter": [
              "lowercase",
              "synonym_filter"
            ]
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "content.data": {
        "type": "text",
        "analyzer": "synonym_analyzer"
      }
    }
  }
}

```

and when I apply my search query

```
  GET /my_index/_doc/_search
 {
    "_source": false,
    "query": {
      "query_string" : {
        "query": "\"earnings per share\"",
        "analyzer":"standard"
     }
    },
    "highlight": {
      "fields": {
        "content.data": {
         "type": "unified",
          "fragment_size": 1000,
          "number_of_fragments": 1
        }
      }
    }
  }

```

Obtained results:

> Now, let's turn our attention to the consolidated results for Q3 and move to Slide 6, let's begin with the revenue line. Revenue increased 1%to $1.44 billion and _ **EPSdecreasedto** _ $2.41 per share. Tim will speak to the components of revenue on the next slide. So let me address the decline in _ **EPS** __numbers_ . _ **EPSfromcontinuing\</em** \> operations declined significantly due to the restructuring charges of $55 million pretax, primarily related to our non-card businesses and a $72 million pre-tax charge_

 

_If we observe the above search result the Elasticsearch is highlighting **EPS, decreased, to** _

 

_But the expected result is EPS or earnings per share_

 

_Why Elasticsearch is highlighting the next two words beside EPS..?_

 

_But when I search for **eps** Elasticsearch highlights the matching words like **eps, EPS, earnings per share.** _

 

_The issue is when searching like **earnings per share, enterprise resource planing**._

 

_Can anyone explain this please and let me know how to avoid it.._

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [December 11, 2019, 9:51am UTC](https://discuss.elastic.co/t/synonym-search-not-working-with-abbreviations/211285/2 "2019-12-11T09:51:55Z")

</div>

Hi,

The default `synonym` filter has difficulties handling multi-word synonyms expansion correctly.  
In 5.x a new filter called `synonym_graph` has been added, it works correctly with multi-words synonym expansion:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-graph-tokenfilter.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-graph-tokenfilter.html)  
It must be applied at query time only ( `search_analyzer` ) and fixes issues when highlighting multi-word synonyms. This [blog post](http://blog.mikemccandless.com/2012/04/lucenes-tokenstreams-are-actually.html) might also provide some context, although its not about the particular highlighting problem, but explains a bit around why multi-word synonyms are tricky beasts.

---

<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:** [January 8, 2020, 9:57am UTC](https://discuss.elastic.co/t/synonym-search-not-working-with-abbreviations/211285/3 "2020-01-08T09:57:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
