---
title: "Indexes: Indexing Basics"
url: "https://docs.ravendb.net/6.2/indexes/indexing-basics"
version: "6.2"
language: "java"
---

# Indexes: Indexing Basics

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/indexes/indexing-basics.md), [Node.js](https://docs.ravendb.net/6.2/indexes/indexing-basics.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

To achieve very fast response times, RavenDB handles **indexing in the background** whenever data is added or changed. This approach allows the server to respond quickly even when large amounts of data have changed. The only drawback of this choice is that results might be stale (more about staleness in next section). Underneath, the server is using [Lucene](http://lucene.apache.org/) to perform indexation and [Raven Query Language](https://docs.ravendb.net/6.2/client-api/session/querying/what-is-rql.md) for querying.

## Stale Indexes

The notion of stale indexes comes from an observation deep in RavenDB's design, assuming that the user should never suffer from assigning the server big tasks. As far as RavenDB is concerned, it is better to be stale than offline, and as such it will return results to queries even if it knows they may not be as up-to-date as possible.

RavenDB returns quickly for every client request, even if involves re-indexing hundreds of thousands of documents. Since the previous request has returned so quickly, the next query can be made a millisecond after that. and results will be returned but they will be marked as `Stale`.

> **Info**
>
> You can read more about stale indexes [here](https://docs.ravendb.net/6.2/indexes/stale-indexes.java.md).

## Querying

RavenDB uses `Raven Query Language (RQL)`, an SQL-like querying language for querying. The easiest way for us would be to expose a method in which you could pass your RQL-flavored query as a string (we [did](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.md#session-advanced-rawquery) that) and do not bother about anything else.

The fact is that we did not stop at this point. We went much further, by exposing querying methods that hides all Lucene syntax complexity:

### Java

```java
List<Employee> employees = session.query(Employee.class, Query.index("Employees/ByFirstName"))
  .whereEquals("FirstName", "Robert")
  .toList();
```

### RQL

```sql
from index 'Employees/ByFirstName'
where FirstName = 'Robert'
```

You can also create queries by using [RawQuery](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.md#session-advanced-rawquery). It is available as a part of advanced session operations:

### RawQuery

```java
List<Employee> employees = session.advanced()
  .rawQuery(Employee.class, "from index 'Employees/ByFirstName' where FirstName = 'Robert'")
  .toList();
```

### RQL

```sql
from index 'Employees/ByFirstName'
where FirstName = 'Robert'
```

## Types of Indexes

You probably know that indexes can be divided by their source of origin to the `static` and `auto` indexes (if not, read about it [here](https://docs.ravendb.net/6.2/indexes/creating-and-deploying.java.md)), but a more interesting division is by functionality. For this case we have `Map` and `Map-Reduce` indexes.

`Map` indexes (sometimes referred as simple indexes) contain one (or more) mapping functions that indicate which fields from documents should be indexed. They indicate which documents can be searched by which fields.

`Map-Reduce` indexes allow complex aggregations to be performed in a two-step process. First by selecting appropriate records (using the Map function), then by applying a specified reduce function to these records to produce a smaller set of results.

> **Info:** Map Indexes {#map-indexes}
>
> You can read more about `Map` indexes [here](https://docs.ravendb.net/6.2/indexes/map-indexes.java.md).

> **Info:** Map-Reduce Indexes {#map-reduce-indexes}
>
> More detailed information about `Map-Reduce` indexes can be found [here](https://docs.ravendb.net/6.2/indexes/map-reduce-indexes.java.md).

## See also

- [Map Indexes](https://docs.ravendb.net/6.2/indexes/map-indexes.java.md)
- [Stale Indexes](https://docs.ravendb.net/6.2/indexes/stale-indexes.java.md)
- [What are Indexes](https://docs.ravendb.net/6.2/indexes/what-are-indexes.java.md)
- [Creating and Deploying Indexes](https://docs.ravendb.net/6.2/indexes/creating-and-deploying.java.md)
- [Query Overview](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.md)
- [What is RQL](https://docs.ravendb.net/6.2/client-api/session/querying/what-is-rql.md)
- [Basics](https://docs.ravendb.net/6.2/indexes/querying/query-index.java.md)
- [Indexes: Overview](https://docs.ravendb.net/6.2/studio/database/indexes/indexes-overview.md#indexes-overview)
- [Studio Index List View](https://docs.ravendb.net/6.2/studio/database/indexes/indexes-list-view.md)
