# \[NEST\] How to move documents/aggregations to another index?

**URL:** <https://discuss.elastic.co/t/nest-how-to-move-documents-aggregations-to-another-index/117176>\
**Category:** Elasticsearch\
**Created:** [January 26, 2018, 9:29am UTC](https://discuss.elastic.co/t/nest-how-to-move-documents-aggregations-to-another-index/117176 "2018-01-26T09:29:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SparkyRih](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sparkyrih/32/24762_2.png) [@SparkyRih](https://discuss.elastic.co/u/SparkyRih)\
**Post date:** [January 26, 2018, 9:29am UTC](https://discuss.elastic.co/t/nest-how-to-move-documents-aggregations-to-another-index/117176/1 "2018-01-26T09:29:45Z")

</div>

I found that it 's possible, but I can't find the solution in the C# library NEST...

I want to aggregate documents by a certain hash value, and move them to a different index, how would I do that in NEST?

---

<div class="post-metadata">

**Author:** ![SparkyRih](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sparkyrih/32/24762_2.png) [@SparkyRih](https://discuss.elastic.co/u/SparkyRih)\
**Post date:** [January 26, 2018, 12:51pm UTC](https://discuss.elastic.co/t/nest-how-to-move-documents-aggregations-to-another-index/117176/2 "2018-01-26T12:51:46Z")

</div>

I did some more research, I think it's better to just give the documents an "archived" field instead of moving the documents to a different index...

---

<div class="post-metadata">

**Author:** ![Melvyn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/melvyn/32/35269_2.png) [@Melvyn](https://discuss.elastic.co/u/Melvyn)\
**Post date:** [January 26, 2018, 2:33pm UTC](https://discuss.elastic.co/t/nest-how-to-move-documents-aggregations-to-another-index/117176/3 "2018-01-26T14:33:40Z")

</div>

I'm not sure if you still need it, but I guess what you need to use in order to move data that has a specific value from an index to another is to use the reindex API:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)

You can specify in the reindex API a query and all the documents matching this query will be moved into a new index.

---

<div class="post-metadata">

**Author:** ![SparkyRih](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sparkyrih/32/24762_2.png) [@SparkyRih](https://discuss.elastic.co/u/SparkyRih)\
**Post date:** [January 26, 2018, 2:54pm UTC](https://discuss.elastic.co/t/nest-how-to-move-documents-aggregations-to-another-index/117176/4 "2018-01-26T14:54:01Z")

</div>

I did already come across that article before I posted this... I was wondering if NEST did support this as well in their library...

But moving documents from one index to another requires reindexing of the indices right? That would take a toll on the performance maybe?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [January 29, 2018, 7:19am UTC](https://discuss.elastic.co/t/nest-how-to-move-documents-aggregations-to-another-index/117176/5 "2018-01-29T07:19:50Z")

</div>

> [@SparkyRih](#):
>
> I did already come across that article before I posted this... I was wondering if NEST did support this as well in their library...

NEST supports the [Reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html) through the `.ReindexOnServer()` method (and the async variant, `ReindexOnServerAsync()`).

> [@SparkyRih](#):
>
> But moving documents from one index to another requires reindexing of the indices right? That would take a toll on the performance maybe?

ReIndex API won't _move_ documents, but reindex them from one index to another. After reindexing, they will still exist in the source index. You could look to delete them using [Delete By Query API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html) which NEST supports through `.DeleteByQuery()`, although be aware that deleting _a lot_ of documents from an index can be a relatively expensive operation compared to reindexing documents from one source index into two new indices.

---

<div class="post-metadata">

**Author:** ![SparkyRih](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sparkyrih/32/24762_2.png) [@SparkyRih](https://discuss.elastic.co/u/SparkyRih)\
**Post date:** [January 29, 2018, 8:28am UTC](https://discuss.elastic.co/t/nest-how-to-move-documents-aggregations-to-another-index/117176/6 "2018-01-29T08:28:53Z")

</div>

Thanks for the extensive answer. I don't think reindexing, moving, deleting documents is a good idea in my situation, giving the documents an extra Boolean parameter is probably a better idea...

The idea is to "archive" certain documents so that I can apply a filter on them to view only non-archived, archived or both... Throwing the documents around will probably make my life a lot harder, and will probably take a lot of resources since the dataset is going to be large...

I thought moving the documents to a second index would make the performance of a query on the main most important/most used index better since I keep the data set of this index small, but I don't think a large dataset is a big issue for Elasticsearch...

---

<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:** [February 26, 2018, 8:29am UTC](https://discuss.elastic.co/t/nest-how-to-move-documents-aggregations-to-another-index/117176/7 "2018-02-26T08:29:16Z")

</div>

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