# Exclude documents from Reindex

**URL:** <https://discuss.elastic.co/t/exclude-documents-from-reindex/343615>\
**Category:** Elasticsearch\
**Tags:** language-clients, reindex\
**Created:** [September 22, 2023, 11:30am UTC](https://discuss.elastic.co/t/exclude-documents-from-reindex/343615 "2023-09-22T11:30:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NekoNova](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nekonova/32/7359_2.png) [@NekoNova](https://discuss.elastic.co/u/NekoNova)\
**Post date:** [September 22, 2023, 11:30am UTC](https://discuss.elastic.co/t/exclude-documents-from-reindex/343615/1 "2023-09-22T11:30:22Z")

</div>

Okay,

I am using the C# NEST client to trigger a Reindex of documents between two indexes in our Elasticsearch. The problem is that the Elasticsearch cluster only moves around 888 documents of the million that is there because the join\_type has changed for a certain document type.

This is the code I am using:

```auto
var reindexResponse = Client.ReindexOnServer(reindexOnServerDescriptor => reindexOnServerDescriptor
            .Source(s => s.Index(Indices.Index(current)))
            .Destination(d => d.Index(Indices.Index(previous)))
            .WaitForCompletion(false)
        );

        var taskId = reindexResponse.Task;
        var taskResponse = Client.Tasks.GetTask(taskId);

        while (!taskResponse.Completed)
        {
            Logger.LogInformation("ElasticSearch Reindexing not completed, waiting 30 seconds...");
            Thread.Sleep(TimeSpan.FromSeconds(30));
            taskResponse = Client.Tasks.GetTask(taskId);
        }

```

I've tried using this instead:

```auto
var reindexResponse = Client.ReindexOnServer(reindexOnServerDescriptor => reindexOnServerDescriptor
            .Source(s => s
                .Index(Indices.Index(current))
                .Query<Company>(x => x.MatchAll())
                .Query<Person>(x => x.MatchAll())
                .Query<Location>(x => x.MatchAll())
                .Query<JobPosting>(x => x.MatchAll())
             )
            .Destination(d => d.Index(Indices.Index(previous)))
            .WaitForCompletion(false)
        );

        var taskId = reindexResponse.Task;
        var taskResponse = Client.Tasks.GetTask(taskId);

        while (!taskResponse.Completed)
        {
            Logger.LogInformation("ElasticSearch Reindexing not completed, waiting 30 seconds...");
            Thread.Sleep(TimeSpan.FromSeconds(30));
            taskResponse = Client.Tasks.GetTask(taskId);
        }

```

The idea is that I only want to move those document types, but the Elasticsearch keeps interrupting the Reindex because it's not excluding the types that cannot be reindexed.

How can I tell Elasticsearch to exclude a specific document from the Reindex?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 20, 2023, 11:31am UTC](https://discuss.elastic.co/t/exclude-documents-from-reindex/343615/2 "2023-10-20T11:31:08Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
