When does index-time boosting make sense?

In the previous section, we discussed boosting queries. This kind of approach to handling differences in the weight of documents is very handy, powerful, and easy to use. It is also sufficient in most situations. However, there are cases when a more convenient way of documents boosting is index-time boosting. One of such use case is the situation when we know which documents are important during the indexing phase. In such a case, we can prepare the document boost and include it as part of the document. We gain a boost that is independent from a query at the cost of reindexing the documents when the boost value is changed (because we need to apply the changed boost). In addition to that, the performance gets slightly better because some parts needed in the boosting process are already calculated at index time, which can matter when your indices have a large number of documents. Information about the boost is stored as a part of the normalization factor and because of that it is important to keep the norms turned on. This means that we can't set norms.enabled to false because we won't be able to use index time boosting.

Defining boosting in the mappings

It is also possible to directly define the field's boost in our mappings. This will result in Elasticsearch giving a boost for all the documents having a value in such a field. Of course, that will also happen during indexing time. The following example illustrates that:

{
  "mappings" : {
    "book" : {
      "properties" : {
        "title" : { "type" : "string" },
        "author" : { "type" : "string", "boost" : 10.0 }
      }
    }
  }
}

Thanks to the preceding boost, all queries will favor values found in the field named author. This also applies to queries using the _all field, because Elasticsearch will apply the boost to values copied between the fields.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset