> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/umbraco-cms/19.latest/develop-with-umbraco/search/extending-search/reindexing-content-programmatically.md).

# Reindexing Content

An article discussing how to trigger reindexing of content programmatically - and when to do it

If you ever need to trigger the reindexing of content manually, you should use the [`IDistributedContentIndexRefresher`](https://github.com/umbraco/Umbraco-CMS/blob/main/src/Umbraco.Core/Search/Indexing/IDistributedContentIndexRefresher.cs) service.

As the name implies, this service ensures that the content reindexing happens correctly across all instances in a load balanced setup. This is important, because some search providers (including the [default provider](/umbraco-cms/19.latest/develop-with-umbraco/search/examine-search-provider.md)) explicitly depend on this behavior.

{% hint style="info" %}
In Umbraco, "content" implies either documents, media or members. However, documents are also named "content", which can be a little confusing.
{% endhint %}

## How to use the service

The service allows for reindexing content, media and members. For content, either draft or published state should be targeted explicitly.

Here's a code sample to show the usage of the service:

{% code title="MyContentReindexer.cs" %}

```csharp
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Search.Indexing;

namespace My.Site.Indexing;

public class MyContentReindexer
{
    private readonly IDistributedContentIndexRefresher _distributedContentIndexRefresher;

    public MyContentReindexer(IDistributedContentIndexRefresher distributedContentIndexRefresher)
        => _distributedContentIndexRefresher = distributedContentIndexRefresher;

    public void ReindexContent(IContent content, bool published)
    {
        var contentState = published ? ContentState.Published : ContentState.Draft;
        _distributedContentIndexRefresher.RefreshContent([content], contentState);
    }

    public void ReindexMedia(IMedia media)
        => _distributedContentIndexRefresher.RefreshMedia([media]);

    public void ReindexMember(IMember member)
        => _distributedContentIndexRefresher.RefreshMember([member]);
}
```

{% endcode %}

## Use with caution

Content reindexing can be an expensive operation, so use it reasonably.

You should *never* allow reindexing to be triggered on demand, for example as part of a page rendering or an API. Doing so could lead to excessive resource usage, and ultimately might bring your site down.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.umbraco.com/umbraco-cms/19.latest/develop-with-umbraco/search/extending-search/reindexing-content-programmatically.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
