# Changing the shard size

**URL:** https://discuss.elastic.co/t/changing-the-shard-size/267359
**Category:** Elasticsearch
**Created:** [March 16, 2021, 11:40am UTC](https://discuss.elastic.co/t/changing-the-shard-size/267359 "2021-03-16T11:40:36Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![sagar\_rao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sagar_rao/32/84702_2.png) [@sagar\_rao](https://discuss.elastic.co/u/sagar_rao)
#### Post date: [March 16, 2021, 11:40am UTC](https://discuss.elastic.co/t/changing-the-shard-size/267359/1 "2021-03-16T11:40:37Z")

</div>

Hi,  
I have Aws elastic search cluster with two nodes. The data is being pushed from fluentd to elastic search. By default all the indexs have 5 primary shards and 1 replica. And i want to resize the no of primary shards to 2 for the new indexes. "I know i can use shrunk api for older indices"

Where can i do this. Indices are created by fluentd itself.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 16, 2021, 1:21pm UTC](https://discuss.elastic.co/t/changing-the-shard-size/267359/2 "2021-03-16T13:21:06Z")

</div>

> [@sagar\_rao](#):
>
> By default all the indexs have 5 primary shards and 1 replica. And i want to resize the no of primary shards to 2 for the new indexes

I don't think you can reduce a 5 shards index to 2 shards. You would need to reindex instead in a new index.  
But you can reduce to 1 shard I think. Here is a typical script to do that on an index `INDEX` in a cluster which has a node with name `NODE1`:

```auto
# Read only and move primaries to one single node and no replica
PUT /INDEX/_settings
{
  "settings": {
    "index.number_of_replicas": 0,
    "index.routing.allocation.require._name": "NODE1", 
    "index.blocks.write": true
  }
}

# Check shards allocation
GET /_cat/shards/INDEX*?v&h=index,shard,prirep,state,docs,node

# Shrink the index
POST /INDEX/_shrink/INDEX_shrunk
{
  "settings": {
    "index.routing.allocation.require._name": null,
    "index.blocks.write": null,
    "index.number_of_replicas": 1,
    "index.number_of_shards": 1 
  }
}

```

> [@sagar\_rao](#):
>
> Where can i do this. Indices are created by fluentd itself.

Check the fluentd documentation. May be you need to change an index template...

> [@sagar\_rao](#):
>
> I have Aws Elasticsearch cluster with two nodes.

BTW did you look at [Cloud by Elastic](https://www.elastic.co/cloud), also available if needed from [AWS Marketplace](https://aws.amazon.com/marketplace/pp/Elasticsearch-Inc-Elasticsearch-Service-on-Elastic/B01N6YCISK), [Azure Marketplace](https://azuremarketplace.microsoft.com/en-us/marketplace/apps/elastic.ec-azure?tab=Overview) and [Google Cloud Marketplace](https://console.cloud.google.com/marketplace/details/endpoints/elasticsearch-service.gcpmarketplace.elastic.co)?

Cloud by elastic is one way to have access to **all features** , all managed by us. Think about what is there yet like Security, Monitoring, Reporting, SQL, Canvas, Maps UI, Alerting and built-in solutions named [Observability](https://www.elastic.co/observability), [Security](https://www.elastic.co/security), [Enterprise Search](https://www.elastic.co/enterprise-search) and what is coming next 🙂 ...

---

<div class="post-metadata">

### Author: ![sagar\_rao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sagar_rao/32/84702_2.png) [@sagar\_rao](https://discuss.elastic.co/u/sagar_rao)
#### Post date: [March 17, 2021, 5:32am UTC](https://discuss.elastic.co/t/changing-the-shard-size/267359/3 "2021-03-17T05:32:49Z")

</div>

Hey Thank you for the reply

I dont want to change shard count for previous indexes . I only want to chnage the or restrict primary shard count to 2 for the new indexes which are going to come in. Is there a way to do that from elastic side. Or it should be done from fluentd end? Note: Fluentd is creating the index as the data coming into it.

---

<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: [March 17, 2021, 5:55am UTC](https://discuss.elastic.co/t/changing-the-shard-size/267359/4 "2021-03-17T05:55:03Z")

</div>

You do that through an index template that matches the index names created by fluentd.

---

<div class="post-metadata">

### Author: ![sagar\_rao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sagar_rao/32/84702_2.png) [@sagar\_rao](https://discuss.elastic.co/u/sagar_rao)
#### Post date: [March 17, 2021, 8:17am UTC](https://discuss.elastic.co/t/changing-the-shard-size/267359/5 "2021-03-17T08:17:08Z")

</div>

How can i change the default value of shards in the cluster settings?

---

<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: [March 17, 2021, 8:18am UTC](https://discuss.elastic.co/t/changing-the-shard-size/267359/6 "2021-03-17T08:18:55Z")

</div>

You need to use [index templates](https://www.elastic.co/guide/en/elasticsearch/reference/7.11/indices-put-template.html).

---

<div class="post-metadata">

### Author: ![sagar\_rao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sagar_rao/32/84702_2.png) [@sagar\_rao](https://discuss.elastic.co/u/sagar_rao)
#### Post date: [March 18, 2021, 9:57am UTC](https://discuss.elastic.co/t/changing-the-shard-size/267359/7 "2021-03-18T09:57:49Z")

</div>

I used this index template

PUT \_template/template\_1  
{  
"index\_patterns": ["te\*", "bar\*"],  
"settings": {  
"number\_of\_shards": 1  
},  
"mappings": {  
"\_source": {  
"enabled": false  
},  
"properties": {  
"host\_name": {  
"type": "keyword"  
},  
"created\_at": {  
"type": "date",  
"format": "EEE MMM dd HH:mm:ss Z yyyy"  
}  
}  
}  
}

Now my indexes are not showing all the fields. should i also add fields to this index template.

If thats the case i cant some fields come in dynamically sometimes.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 18, 2021, 12:48pm UTC](https://discuss.elastic.co/t/changing-the-shard-size/267359/8 "2021-03-18T12:48:16Z")

</div>

Why did you disable the source field?

---

<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: [April 15, 2021, 12:48pm UTC](https://discuss.elastic.co/t/changing-the-shard-size/267359/9 "2021-04-15T12:48:54Z")

</div>

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