---
title: "Changes API: How to Subscribe to Index Changes"
url: "https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-index-changes"
version: "6.2"
language: "csharp"
---

# Changes API: How to Subscribe to Index Changes

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

> **Note**
>
> Subscribe to index changes using `ForIndex` or `ForAllIndexes`.
>
> > **Warning**
> >
> > The `Subscribe` method on the observable these methods return accepts only an `IObserver` object
> > by default.  
> > To instead subscribe with a delegate, like the `change => ...` lambda used in the examples below,
> > add the [System.Reactive](https://www.nuget.org/packages/System.Reactive/) package to your project.  
> > This adds `Subscribe` overloads that take delegates, including ones with error and
> > completion handlers.
>
> - In this article:
>   - [ForIndex](#forindex)
>   - [ForAllIndexes](#forallindexes)
>   - [IndexChange and IndexChangeTypes syntax](#indexchange-and-indexchangetypes-syntax)

## ForIndex {#forindex}

Index changes for one index can be observed using `ForIndex` method.

### Syntax

```csharp
IChangesObservable<IndexChange> ForIndex(string indexName);
```

| Parameters | | |
| - | - | - |
| **indexName** | string | Name of an index for which notifications will be processed. |

| Return Value | |
| - | - |
| IChangesObservable<[IndexChange](#indexchange-and-indexchangetypes-syntax)> | Observable that allows to add subscriptions to notifications for index with given name. |

### Example

```csharp
IDisposable subscription = store
    .Changes()
    .ForIndex("Orders/All")
    .Subscribe(
        change =>
        {
            switch (change.Type)
            {
                case IndexChangeTypes.None:
                    //Do someting
                    break;
                case IndexChangeTypes.BatchCompleted:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexAdded:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexRemoved:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexDemotedToIdle:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexPromotedFromIdle:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexDemotedToDisabled:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexMarkedAsErrored:
                    //Do someting
                    break;
                case IndexChangeTypes.SideBySideReplace:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexPaused:
                    //Do someting
                    break;
                case IndexChangeTypes.LockModeChanged:
                    //Do someting
                    break;
                case IndexChangeTypes.PriorityChanged:
                    //Do someting
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        });
```

## ForAllIndexes {#forallindexes}

Index changes for all indexex can be observed using `ForAllIndexes` method.

### Syntax

```csharp
IChangesObservable<IndexChange> ForAllIndexes();
```

| Return Value | |
| - | - |
| IChangesObservable<[IndexChange](#indexchange-and-indexchangetypes-syntax)> | Observable that allows to add subscriptions to notifications for all indexes. |

### Example

```csharp
IDisposable subscription = store
    .Changes()
    .ForAllIndexes()
    .Subscribe(change => Console.WriteLine("{0} on index {1}", change.Type, change.Name));
```

## IndexChange and IndexChangeTypes syntax {#indexchange-and-indexchangetypes-syntax}

### IndexChange

**The notification object delivered to subscribers when an index changes.**

```csharp
class IndexChange
{
    IndexChangeTypes Type
    string Name
}
```

| Property | Type | Description |
| - | - | - |
| **Type** | [IndexChangeTypes](#indexchange-and-indexchangetypes-syntax) | Change type |
| **Name** | string | Index name |

### IndexChangeTypes

```csharp
enum IndexChangeTypes
{
    None,
    BatchCompleted,
    IndexAdded,
    IndexRemoved,
    IndexDemotedToIdle,
    IndexPromotedFromIdle,
    IndexDemotedToDisabled,
    IndexMarkedAsErrored,
    SideBySideReplace,
    Renamed,
    IndexPaused,
    LockModeChanged,
    PriorityChanged,
    RollingIndexChanged,
}
```

| Name | Value |
| - | - |
| **None** | `0` |
| **BatchCompleted** | `1` |
| **IndexAdded** | `8` |
| **IndexRemoved** | `16` |
| **IndexDemotedToIdle** | `32` |
| **IndexPromotedFromIdle** | `64` |
| **IndexDemotedToDisabled** | `256` |
| **IndexMarkedAsErrored** | `512` |
| **SideBySideReplace** | `1024` |
| **Renamed** | `2048` |
| **IndexPaused** | `4096` |
| **LockModeChanged** | `8192` |
| **PriorityChanged** | `16384` |
| **RollingIndexChanged** | `65536` |

## See also

- [What is Changes API](https://docs.ravendb.net/6.2/client-api/changes/what-is-changes-api.md)
- [How to Subscribe to Operation Changes](https://docs.ravendb.net/6.2/client-api/changes/how-to-subscribe-to-operation-changes.md)
