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

# Put Indexes Operation

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

> **Note**
>
> - There are a few ways to create and deploy indexes in a database.
>
> - This page describes deploying a **static-index** using the `PutIndexesOperation` Operation.  
>   For a general description of Operations see [what are operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.nodejs.md).
>
> - In this page:
>   - [Ways to deploy indexes - short summary](#ways-to-deploy-indexes---short-summary)
>   - [Put indexes operation with IndexDefinition](#put-indexes-operation-with-indexdefinition)
>   - [Syntax](#syntax)

## Ways to deploy indexes - short summary

> **Note**
>
> ##### Static-indexes:
>
> There are a few ways to deploy a static-index from the Client API:
>
> - The following methods are explained in section [Deploy a static-index](https://docs.ravendb.net/6.2/indexes/creating-and-deploying.nodejs.md#deploy-a-static-index):
>   - Call `execute()` on a specific index instance.
>   - Call `executeIndex()` or `executeIndexes()` on your *DocumentStore* object.
>   - Call `IndexCreation.createIndexes()`.
>
> - Alternatively, you can execute the `PutIndexesOperation` maintenance operation on the *DocumentStore*, **as explained below**.

> **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.nodejs.md#auto-indexes).

## Put indexes operation with IndexDefinition

Using `PutIndexesOperation` with **IndexDefinition** allows you to:

- Choose any name for the index.  
  This string-based name is specified when querying the index.
- Set low-level properties available in *IndexDefinition*.

### LINQ-index

```javascript
// Create an index definition
const indexDefinition = new IndexDefinition();

// Name is mandatory, can use any string
indexDefinition.name = "OrdersByTotal";

// Define the index map functions, string format
// A single string for a map-index, multiple strings for a multi-map-index
indexDefinition.maps = new Set([`
  // Define the collection that will be indexed:
  from order in docs.Orders

      // Define the index-entry:
      select new 
      {
          // Define the index-fields within each index-entry:
          Employee = order.Employee,
          Company = order.Company,
          Total = order.Lines.Sum(l => (l.Quantity * l.PricePerUnit) * (1 - l.Discount))
      }`
]);

// indexDefinition.reduce = ...

// Can provide other index definitions available on the IndexDefinition class
// Override the default values, e.g.:
indexDefinition.deploymentMode = "Rolling";
indexDefinition.priority = "High";
indexDefinition.configuration = {
  "Indexing.IndexMissingFieldsAsNull": "true"
};
// See all available properties in syntax below

// Define the put indexes operation, pass the index definition
// Note: multiple index definitions can be passed, see syntax below
const putIndexesOp = new PutIndexesOperation(indexDefinition);

// Execute the operation by passing it to maintenance.send
await documentStore.maintenance.send(putIndexesOp);
```

### JavaScript-index

```javascript
// Create an index definition
const indexDefinition = new IndexDefinition();

// Name is mandatory, can use any string
indexDefinition.name = "OrdersByTotal";

// Define the index map functions, string format
// A single string for a map-index, multiple strings for a multi-map-index
indexDefinition.maps = new Set([`
  map('Orders', function(order) {
      return {
          Employee: order.Employee,
          Company: order.Company,
          Total: order.Lines.reduce(function(sum, l) {
              return sum + (l.Quantity * l.PricePerUnit) * (1 - l.Discount);
          }, 0)
      };
  });`
]);

// indexDefinition.reduce = ...

// Can provide other index definitions available on the IndexDefinition class
// Override the default values, e.g.:
indexDefinition.deploymentMode = "Rolling";
indexDefinition.priority = "High";
indexDefinition.configuration = {
  "Indexing.IndexMissingFieldsAsNull": "true"
};
// See all available properties in syntax below

// Define the put indexes operation, pass the index definition
// Note: multiple index definitions can be passed, see syntax below
const putIndexesOp = new PutIndexesOperation(indexDefinition);

// Execute the operation by passing it to maintenance.send
await documentStore.maintenance.send(putIndexesOp);
```

## Syntax

```javascript
const putIndexesOperation = new PutIndexesOperation(indexesToAdd);
```

| Parameter | Type | Description |
| - | - | - |
| **indexesToAdd** | `...IndexDefinition[]` | Definitions of indexes to deploy |

| `IndexDefinition` parameter | Type | Description |
| - | - | - |
| name | `string` | Name of the index, a unique identifier |
| maps | `Set<string>` | All the map functions for the index |
| reduce | `string` | The index reduce function |
| deploymentMode | `object` | Deployment mode<br />(Parallel, Rolling) |
| state | `object` | State of index<br />(Normal, Disabled, Idle, Error) |
| priority | `object` | Priority of index<br />(Low, Normal, High) |
| lockMode | `object` | Lock mode of index<br />(Unlock, LockedIgnore, LockedError) |
| fields | `Record<string, object>` | *IndexFieldOptions* per index field |
| additionalSources | `Record<string, string>` | Additional code files to be compiled with this index |
| additionalAssemblies | `object[]` | Additional assemblies that are referenced |
| configuration | `object` | Can override [indexing configuration](https://docs.ravendb.net/6.2/server/configuration/indexing-configuration.md) by setting this Record\<string, string> |
| outputReduceToCollection | `string` | A collection name for saving the reduce results as documents |
| reduceOutputIndex | `number` | This number will be part of the reduce results documents IDs |
| patternForOutputReduceToCollectionReferences | `string` | Pattern for documents IDs which reference IDs of reduce results documents |
| patternReferencesCollectionName | `string` | A collection name for the reference documents created based on provided pattern |

| `store.maintenance.send(putIndexesOp)` return value | Description |
| - | - |
| `object[]` | operation result per index |

| Operation result per index | Type | Description |
| - | - | - |
| index | `string` | Name of the index that was added |
| raftCommandIndex | `long` | Index of raft command that was executed |

## See also

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