A synonym-aware search

Elasticsearch considers synonyms while searching. This means that if you search for the word "big", a document would be matched even if any of the synonyms of the word big, such as "large", are present in that document.

Let's see how we can implement a simple synonym filter and how it works under the hood:

curl -X PUT "http://localhost:9200/news" -d '{
  "analysis": {
    "filter": {
      "synonym": {
        "type": "synonym",
        "synonyms": [
          "big, large",
          "round, circle"
        ]
      }
    },
    "analyzer": {
      "synonymAnalyzer": {
        "type": "custom",
        "tokenizer": "standard",
        "filter": [
          "lowercase",
          "synonym"
        ]
      }
    }
  }
}'

Here, we created a synonym filter and provided a set of synonyms in it. Elasticsearch does not have a standard dictionary of synonyms so we need ...

Get Elasticsearch Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.