O'Reilly logo

Mastering Elasticsearch 5.x - Third Edition by Bharvi Dixit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting a per-field similarity

Since Elasticsearch 0.90, we are allowed to set a different similarity for each of the fields we have in our mappings. For example, let's assume that we have the following simple mappings that we use in order to index blog posts (stored in the posts_no_similarity.json file):

{ 
  "mappings" : { 
    "post" : { 
      "properties" : { 
        "id" : { "type" : "long", "store" : "yes" }, 
        "name" : { "type" : "text", "store" : "yes", "index" :  
          "analyzed" }, 
        "contents" : { "type" : "text", "store" : "no", "index" :  
        "analyzed" } 
      } 
    } 
 } 
} 

What we would like to do is use the classic similarity model for the name field and the contents field. In order to do this, we need to extend our field definitions and add the similarity property with the value ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required