liveBook · Manning

Synonym

As explained in Elasticsearch in Action, Second Edition

A synonym is an alternative word or phrase treated as semantically equivalent to another word for search or text processing.

A synonym lets search treat different words or phrases as equivalent. Without synonym handling, a query for “passion” may miss text containing the related term “cognizance”; with it, varied user vocabulary can produce more relevant results. section 7.1.1 section 1.3.1

Synonyms support search behavior in several ways:

  • Map alternate names such as “soccer” and “football” so either query can point to a football game. section 7.8.3
  • Enrich normalization alongside stemming and stop-word handling before terms are added to the inverted index. section 7.2.2
  • Address vocabulary variation that exact matching, including traditional database search, may fail to understand. section 1.2.3

Configure a synonym filter

Create an index analysis filter with a rule such as “soccer => football”. Test the configured analyzer with “What’s soccer?” through the _analyze API; the analyzed output includes “football”, showing that the synonym was applied. For larger or changing synonym sets, load rules from synonyms.txt through synonyms_path instead of hardcoding them. section 7.8.3

Listing 7.52 Creating an index with a synonym filter
PUT index_with_synonyms
{
  "settings": {
    "analysis": {
      "filter": {
        "synonyms_filter":{
          "type":"synonym",
          "synonyms":[ "soccer => football"]
        }
      }
    }
  }
}

Shows the Elasticsearch index settings needed to define a synonym token filter and map soccer to football. section 7.8.3

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines synonyms and demonstrates token-filter configuration, _analyze testing, and filesystem loading without detailing token-stream internals.
Examples
Uses passion, cognizance, soccer, football, author, writer, and synonyms.txt to demonstrate missed matches, mappings, and normalization.
What it assumes
Builds on analyzers, tokenizers, filters, and normalization while introducing synonym rules through concrete Elasticsearch settings.
What you can do after
Apply it via an Elasticsearch synonym token filter, _analyze API, or synonyms_path file to test and maintain synonym mappings.
How it connects
Connects synonyms with text analysis, analyzers, tokenization, normalization, stemming, stop words, inverted indexes, and fuzzy matching.

Also explained in

Compare how 2 books explain synonym →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.