---
title: "Put Indexes Operation"
url: "https://docs.ravendb.net/6.2/client-api/operations/maintenance/indexes/put-indexes"
version: "6.2"
language: "java"
---

# Put Indexes Operation

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/client-api/operations/maintenance/indexes/put-indexes.md), [Python](https://docs.ravendb.net/6.2/client-api/operations/maintenance/indexes/put-indexes.python.md), [PHP](https://docs.ravendb.net/6.2/client-api/operations/maintenance/indexes/put-indexes.php.md), [Node.js](https://docs.ravendb.net/6.2/client-api/operations/maintenance/indexes/put-indexes.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."

**PutIndexesOperation** is used to insert indexes into a database.

> **Note:** Auto-indexes
>
> RavenDB uses a suitable existing auto-index, or creates one if needed,  
> when a dynamic query includes **one or more of the following**:
>
> - A `where` condition on fields other than the document ID,  
>   or an ID condition other than a simple ID lookup (`id() = ...`, `id() in (...)`, `startsWith(id(), ...)`).
> - An `order by` clause to sort the results.
> - A `group by` clause to group the results.
> - A `suggest()` call in the `select` clause to request term suggestions.
>
> Learn more in [Creating auto indexes](https://docs.ravendb.net/6.2/indexes/creating-and-deploying.java.md#auto-indexes).

## Syntax

```java
PutIndexesOperation(IndexDefinition... indexToAdd)
```

| Parameters | | |
| - | - | - |
| **indexToAdd** | `IndexDefinition...` | Definitions of indexes |

| Return Value | |
| - | - |
| PutIndexResult\[] | List of created indexes |

## Example I

```java
IndexDefinition indexDefinition = new IndexDefinition();
indexDefinition.setMaps(Collections.singleton("from order in docs.Orders select new { " +
  "   order.Employee," +
  "   order.Company," +
  "   Total = order.Lines.Sum(l => (l.Quantity * l.PricePerUnit) * (1 - l.Discount))" +
  "}"));

store.maintenance().send(new PutIndexesOperation(indexDefinition));
```

## Example II

```java
IndexDefinitionBuilder builder = new IndexDefinitionBuilder();
builder.setMap("from order in docs.Orders select new { " +
  "   order.Employee," +
  "   order.Company," +
  "   Total = order.Lines.Sum(l => (l.Quantity * l.PricePerUnit) * (1 - l.Discount))" +
  "}");

IndexDefinition definition = builder.toIndexDefinition(store.getConventions());
store.maintenance()
  .send(new PutIndexesOperation(definition));
```

## See also

- [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)
- [Index Administration](https://docs.ravendb.net/6.2/indexes/index-administration.md)
- [What are operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.java.md)
- [How to Get Indexes](https://docs.ravendb.net/6.2/client-api/operations/maintenance/indexes/get-indexes.java.md)
- [How to Delete Index](https://docs.ravendb.net/6.2/client-api/operations/maintenance/indexes/delete-index.java.md)
- [How to Reset Index](https://docs.ravendb.net/6.2/client-api/operations/maintenance/indexes/reset-index.java.md)
