3 RavenDB indexes
This chapter covers
- The indexing process
- Creating an index and querying it
- Map-only and Map/Reduce indexes
So far we’ve been operating on the assumption that querying with RavenDB “just works.” Although this still holds true, starting with this chapter we’re going to explain exactly how it works.
We don’t need to go far to come up with an example to demonstrate what a crucial part indexes play in answering queries. This is exactly like going to a library with millions of books and trying to find one book on the thousands of shelves. And when you find that book, you must find the one page out of the hundreds of pages it contains that mentions the topic you’re interested in. If the library has a decent catalog, this will take a matter of minutes. Otherwise, you may spend a whole weekend there before getting to the right book.
Without indexes it’s impossible to find data on anything other than the document ID in RavenDB, and therefore RavenDB becomes just a bloated key/value store. Indexes are the piece of the puzzle that allows rich queries for data to be satisfied efficiently.
Luckily, RavenDB automatically creates and manages indexes for most common queries, but for some cases you’ll have to create indexes yourself. Understanding the query life cycle, when creating indexes manually is required and how those indexes are structured, is going to help you with building complex software with RavenDB.