Book Image

ElasticSearch Blueprints

Book Image

ElasticSearch Blueprints

Overview of this book

Table of Contents (15 chapters)
Elasticsearch Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

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 to provide it ourselves.

Let's apply our analyzer on some sample text using the analyzer API and examine the result...