What are indexes?

Indexes are server-side functions that define which fields (and what values) documents can be searched on and are the only way to satisfy queries in RavenDB. The whole indexing process is done in the background and is triggered whenever data is added or changed. This approach allows the server to respond quickly even when large amounts of data have changed and avoids costly table scan operations. A consequence of this choice is that the results might be stale, and you can read more about this (including mitigation techniques) on the Stale Indexes) page.

The core of every index is its mapping function that utilizes LINQ-like syntax, and the result of such a mapping is converted to a Lucene index entry, which is persisted for future use to avoid re-indexing each time the query is issued and keep response times minimal.

Basic example

In our example, we will create an index that will map documents from the Employeescollection and enable querying by FirstName, LastName, or both.

first, we need to create an index. One way to create it is to use the AbstractIndexCreationTask, but there are other ways available as well (you can read about them here).