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 ...

Get Mastering Elasticsearch 5.x - Third Edition 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.