Synonym search not working with abbreviations

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 EPS decreased to $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 . EPS from continuing</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..

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
It must be applied at query time only ( search_analyzer ) and fixes issues when highlighting multi-word synonyms. This blog post 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.

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