# Shrink and split APIs

**URL:** <https://discuss.elastic.co/t/shrink-and-split-apis/308752>\
**Category:** Elasticsearch\
**Created:** [July 3, 2022, 4:31pm UTC](https://discuss.elastic.co/t/shrink-and-split-apis/308752 "2022-07-03T16:31:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ewolfman](https://avatars.discourse-cdn.com/v4/letter/e/5f8ce5/32.png) [@ewolfman](https://discuss.elastic.co/u/ewolfman)\
**Post date:** [July 3, 2022, 4:31pm UTC](https://discuss.elastic.co/t/shrink-and-split-apis/308752/1 "2022-07-03T16:31:31Z")

</div>

Hi,

I tried the shrink API on a 30GB index and shrinked from 15 shards to 5 shards.  
What I am not sure about is that this seemed to have happened instantaneously.  
I checked the \_cat/recovery endpoint and saw that there are ongoing tasks there, but when I was using \_count or \_search it looked like the count was correct and that the search found what I was looking for.

In the shrink doc it is stated: "Hard-links segments from the source index into the target index". So I thought that maybe both indices point to the same segments behind the scenes and that is maybe why it appeared very quick. Yet when I made an update to a document in the target index it was not reflected to the source index (which is what I hoped for).

Can someone explain what actually happens behind the scenes? I read [here](https://discuss.elastic.co/t/what-the-difference-between-shrink-api-and-reindex-api/228063/2) that "The shrink index API combines the existing segments without reprocessing". So there is some kind of copy-merge of the existing segments onto the new index (which was apparantely not complete as i saw in the \_cat/recovery). Just wondering how come the \_count, \_search, \_update were already working for the new index while the process was still ongoing?

And one more question: [here](https://discuss.elastic.co/t/how-do-i-increase-or-reduce-the-shard-count-of-an-existing-index/242704) it is mentioned that "Once it's all done, you probably want to remove the original index". What happens if you delete the older index while \_cat/recovery still shows progress? Is Elasticsearch smart enough NOT to delete the source index segments while shrinking is still ongoing?

Thanks.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [July 4, 2022, 7:58am UTC](https://discuss.elastic.co/t/shrink-and-split-apis/308752/2 "2022-07-04T07:58:27Z")

</div>

Yes it typically uses hard-linking which is very fast. This works because the files on disk are immutable so any changes in one index won't be reflected in the other.

Similarly it's fine to delete the source index as soon as the target index is reported as healthy. With hard-linking, deleting one link to the underlying data won't affect any other links.

---

<div class="post-metadata">

**Author:** ![ewolfman](https://avatars.discourse-cdn.com/v4/letter/e/5f8ce5/32.png) [@ewolfman](https://discuss.elastic.co/u/ewolfman)\
**Post date:** [July 4, 2022, 3:32pm UTC](https://discuss.elastic.co/t/shrink-and-split-apis/308752/3 "2022-07-04T15:32:22Z")

</div>

> Similarly it's fine to delete the source index as soon as the target index is reported as healthy

Do you mean when the new index becomes yellow (due to replicas) or green? or is there some other way to know for sure that the older index can be deleted without risk or losing data?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [July 4, 2022, 4:11pm UTC](https://discuss.elastic.co/t/shrink-and-split-apis/308752/4 "2022-07-04T16:11:10Z")

</div>

I'd recommend waiting for `green` health.

---

<div class="post-metadata">

**Author:** ![ewolfman](https://avatars.discourse-cdn.com/v4/letter/e/5f8ce5/32.png) [@ewolfman](https://discuss.elastic.co/u/ewolfman)\
**Post date:** [July 4, 2022, 9:42pm UTC](https://discuss.elastic.co/t/shrink-and-split-apis/308752/5 "2022-07-04T21:42:57Z")

</div>

Thanks very much.

---

<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:** [August 1, 2022, 9:43pm UTC](https://discuss.elastic.co/t/shrink-and-split-apis/308752/6 "2022-08-01T21:43:24Z")

</div>

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