RavenDB 4.0Raven Query Language

time to read 3 min | 592 words

The last big feature for RavenDB 4.0 has landed, and it is a big one. You can see the details on the PR that implemented this feature below, but you probably care a lot more about what it is.

RavenDB uses Lucene as the underlying index technology, and until now we simply exposed (slightly modified) Lucene syntax to our clients. That was easy to do and quite effective, but it also meant that we were limited to somewhat arcane query language and what it could do.

In RavenDB 4.0, we now have a full query language, and you can see how this looks like below:

image

This will be produce the results that you expect, giving you all the companies residing in London in the database.

The rest of the system behaves just the same, this query is going to hit the query optimizer, and index will be created if one does not already exists, etc. It is just that our query language is both much nicer to look at and allow us to work with it in a much more structured manner (and yes, that is a pun).

We also support aggregation:

image

Which gives:

image

This is automatically creating a map/reduce index and does all the work for you. We also have support for querying on indexes directly via:

image

If you are familiar with how we used to have to do range queries, you can see how big an improvement this is. This is actually a pretty significant feature, because you can define a static index to do whatever you want with the data, and then query on top of that.

You can also do the usual full text operations directly in the query language:

image

We decide to go with the method abstraction for most operations, because it allows us a lot of freedom in the syntax and give very readable queries.

Here is an example of us trying a more complex query. In this one, I want to find companies in London, the UK or France. But instead of just wanting to find them in that particular order, I want to get them with ranking.

image

I really want a company in London, so that should sort first, and then UK based companies and finally France companies. You can see the results of the query below. This query also show have we can do projections, in a much nicer way.

image

The feature just landed in the main branch and we are now working through all of the rough edges, but it is very exciting, since it give you a natural way to query RavenDB without losing any of the power.

I mentioned that this was a big change, right?

image

And that is just for the C# work, we still have to update the other clients.

More posts in "RavenDB 4.0" series:

  1. (13 Oct 2017) Interlocked distributed operations
  2. (12 Oct 2017) Node.JS client is now in beta
  3. (11 Sep 2017) Support options
  4. (14 Aug 2017) Maintaining transaction boundary integrity in a distributed cluster
  5. (03 Aug 2017) Raven Query Language
  6. (13 Jul 2017) The admin’s backdoor is piping hot
  7. (10 Jul 2017) Securing the keys to the kingdom
  8. (04 Jul 2017) Unbounded results sets
  9. (13 Jun 2017) The etag simplification
  10. (12 Jun 2017) Data subscriptions, Part II
  11. (09 Jun 2017) Data subscriptions, Part I
  12. (19 May 2017) Managing encrypted databases
  13. (11 May 2017) Working with attachments
  14. (10 May 2017) Attachments
  15. (08 May 2017) Full database encryption