Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive

RavenDBIndex Boosting

time to read 6 min | 1084 words

Recently we added a really nice feature, boosting the results while indexing.

Boosting is a way to give documents or attributes in a document weights. Attribute level boosting is a way to tell RavenDB that a certain  attribute in a document is more important than the others, so it will show up higher in queries when other properties are involved in a query. A document level boosting means that a certain document is more important than another (when using multi maps).

Let us see a few examples where this is happening. The simplest scenario is when we have a multi field search, and we want one of the fields to be the more important one. For example, we decided that when you make a search for first name and last name, a match on the first name has higher relevance than a match on the last name. We can define this requirement with the following index:

public class Users_ByName : AbstractIndexCreationTask<User>
    public Users_ByName()
        Map = users => from user in users
                       select new
                           FirstName = user.FirstName.Boost(3),

And we can query the index using:

var matches = session.Query<User,UsersByName>()
      .Where(x=>x.FirstName == "Ayende" || x.LastName == "Eini")

Assuming that we have a user with the first name “Ayende” and another user with the last name “Eini”, this will find both of them, but will rank the user with the name “Ayende” first.

Let us see another variant, we have a multi map index for users and accounts, both are searchable by name, but we want to ensure that accounts are more important than users. We can do that using the following index:

public class UsersAndAccounts : AbstractMultiMapIndexCreationTask
    public UsersAndAccounts()
        AddMap<User>(users =>
                     from user in users
                     select new {Name = user.FirstName}
        AddMap<Account>(accounts =>
                        from account in accounts
                        select new {account.Name}.Boost(3)

If we have query that has matches for users and accounts, this will make sure that the account comes first.

And finally, a really interesting use case is that based on the entity itself, you decide to rank it higher. For example, we want to rank customers that ordered a lot from us higher than other customers. We can do that using the following index:

public class Accounts_Search : AbstractIndexCreationTask<Account>
    public Accounts_Search()
        Map = accounts =>
              from account in accounts
              select new
              }.Boost(account.TotalIncome > 10000 ? 3 : 1);

This way, we get the more important customers first. And this is really one of those things that brings up the polish in the system, the things that makes the users sit up and take notice.

More posts in "RavenDB" series:

  1. (22 May 2015) Adding a new shard to an existing cluster, splitting the shard
  2. (21 May 2015) Adding a new shard to an existing cluster, the easy way
  3. (18 May 2015) Enabling shards for existing database


Lam Chan

That is very awesome. I'm looking forward to your feature set expansions!

Lam Chan

That is very awesome. I'm looking forward to your feature set expansions!


How is this better than order by?


Where is the source for the AbstractIndexCreationTask and AbstractMultiMapIndexCreationTask?

From this angle, your method for isolating query logic looks similar to the specification pattern implementation that you were less than enthusiastic about (see here: http://ayende.com/blog/4784/architecting-in-the-pit-of-doom-the-evils-of-the-repository-abstraction-layer). But, I'm guessing it just seems that way because I don't know what the base classes are actually doing.


Nevermind (https://github.com/ravendb/ravendb/blob/master/Raven.Client.Lightweight/Indexes/AbstractIndexCreationTask.cs)


How do you handle ordering when using boosting? Never use ordering? Will Skip/Take blow up for not being ordered?


Same question as Jonty. Also what if You decide that Firstname is more important then AccountName?


@Oren: is the value of the Boost available as a field in the result, or at least usable to specify a different ordering? Something like "order by boost desc" or something like that.

Ayende Rahien

Jonty, It is important because it makes the values not dependent on strict ordering, but their basic importance as it relates to your actual query.

Ayende Rahien

Njy, I don't understand the question


Using Boost gives more "importance" to some results, which actually means doing a (logical) additional "order by", is that correct?

If it is like so, i was wondering if it could be possible - for example - to search news articles by a search term and get the results ordered by the date (to get the most recent firsts) and then, if the date is the same, by "boost value". It's just an example, i hope to have clarified the hypothetical scenario.

Ayende Rahien

Njy, I actually think that this would work, yes. Itamar can probably answer this better, but I am pretty sure that the boost value would only be a factor inside the same orderby value.


Ok, thanks

Itamar Syn-Hershko

njy, the "score" will be computed using the sort by and the boost will be factored in. So yes - this is essentially what will happen.

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats