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

Substring matching


By now, you would have noticed that only exact word matches are taken as result qualifiers. What if I want an incomplete token or word to be matched?

For example, when I search for titani, it should match against titanium because titani is an incomplete form of titanium.

For this kind of purpose, it would be best to use the EdgeNGram-based analyzer.

First let's create the analyzer:

curl -X PUT "http://localhost:9200/my-index" -d '{
  "index": {
    "number_of_shards": 1,
    "number_of_replicas": 1
  },
  "analysis": {
    "filter": {
      "ngram": {
        "type": "edgeNgram",
        "min_gram": 1,
  "max_gram" : 50
      }
    },
    "analyzer": {
      "NGramAnalyzer": {
        "type": "custom",
        "tokenizer" : "standard", 
        "filter": "ngram"
      }
    }
  } 
}'  

Here, we are creating an edge NGram filter, which creates substrings of all the tokens from one end of the token with the minimum length of two and the maximum length of 50.

Let's see what its...