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 of the chosen similarity name. Our changed mappings (stored in the posts_similarity.json
file) would...