# Increasing the number of index shards

**URL:** <https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377>\
**Category:** Elasticsearch\
**Created:** [October 25, 2022, 7:50am UTC](https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377 "2022-10-25T07:50:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZahraZare](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zahrazare/32/112102_2.png) [@ZahraZare](https://discuss.elastic.co/u/ZahraZare)\
**Post date:** [October 25, 2022, 7:50am UTC](https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377/1 "2022-10-25T07:50:00Z")

</div>

Is it possible to change the number of shards of existing indices? How to do this with Python?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 25, 2022, 7:52am UTC](https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377/2 "2022-10-25T07:52:46Z")

</div>

You can change the number of replica shards, but not the number of primary shards. You can however use the [split index API](https://www.elastic.co/guide/en/elasticsearch/reference/8.4/indices-split-index.html) to create a new index with a different number of primary shards based on an existing index. If you have an alias in front of your index you can then reroute it after the split, but it requires you to stop indexing/updating/deleting traffic for a period of time.

---

<div class="post-metadata">

**Author:** ![ZahraZare](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zahrazare/32/112102_2.png) [@ZahraZare](https://discuss.elastic.co/u/ZahraZare)\
**Post date:** [October 25, 2022, 8:24am UTC](https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377/3 "2022-10-25T08:24:06Z")

</div>

Hello @Christian_Dahlqvist , thank you for always helping me. I want to change the number of shards of each index to 100 if it is, for example, 50.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 25, 2022, 8:32am UTC](https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377/4 "2022-10-25T08:32:45Z")

</div>

I assume we are talking about primary shards. What is driving this change?

To do that you will need to use the API I pointed to.

---

<div class="post-metadata">

**Author:** ![ZahraZare](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zahrazare/32/112102_2.png) [@ZahraZare](https://discuss.elastic.co/u/ZahraZare)\
**Post date:** [October 25, 2022, 8:59am UTC](https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377/5 "2022-10-25T08:59:43Z")

</div>

Does that mean I have to use this API for each and every existing index?!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 25, 2022, 9:01am UTC](https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377/6 "2022-10-25T09:01:44Z")

</div>

Yes.

How many indices do you have that need to scale out?

What is the average size of these?

Why are you scaling out?

Be aware that having lots of small shards can be very inefficient and cause performance problems.

---

<div class="post-metadata">

**Author:** ![ZahraZare](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zahrazare/32/112102_2.png) [@ZahraZare](https://discuss.elastic.co/u/ZahraZare)\
**Post date:** [October 25, 2022, 9:39am UTC](https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377/7 "2022-10-25T09:39:56Z")

</div>

This is just a task assigned to me and it is important to write the python code. I thought I could do it with a for loop:)

---

<div class="post-metadata">

**Author:** ![ZahraZare](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zahrazare/32/112102_2.png) [@ZahraZare](https://discuss.elastic.co/u/ZahraZare)\
**Post date:** [October 25, 2022, 10:47am UTC](https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377/8 "2022-10-25T10:47:00Z")

</div>

@Christian_Dahlqvist Can I use max\_result \_window for this?

---

<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:** [November 22, 2022, 10:47am UTC](https://discuss.elastic.co/t/increasing-the-number-of-index-shards/317377/9 "2022-11-22T10:47:33Z")

</div>

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