# How many Primary and Replica shards will be allotted for a Dynamic elasticsearch Index (ex:index =\> "sample-%(YYYY.MM.DD)")

**URL:** https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460
**Category:** Elasticsearch
**Created:** [August 17, 2017, 5:09pm UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460 "2017-08-17T17:09:42Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![rajesh](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@rajesh](https://discuss.elastic.co/u/rajesh)
#### Post date: [August 17, 2017, 5:09pm UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460/1 "2017-08-17T17:09:42Z")

</div>

Hi,

My logstash is indexing to a dynamic index "sample-%(YYYY.MM.DD)"). I have assigned Primary Shards and Replica shards as 3 and 2 respectively. But when logstash sends to the dynamic index it's creating an index(sample-2017.08.17) with 5 primary shards and 1 replica. Why is it not 3 Primary and 2 Replica?

Thanks in advance..

---

<div class="post-metadata">

### Author: ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)
#### Post date: [August 18, 2017, 12:06am UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460/2 "2017-08-18T00:06:23Z")

</div>

> [@rajesh](#):
>
> I have assigned Primary Shards and Replica shards as 3 and 2 respectively.

What operations have you performed to make this assignment?

---

<div class="post-metadata">

### Author: ![rajesh](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@rajesh](https://discuss.elastic.co/u/rajesh)
#### Post date: [August 20, 2017, 4:24pm UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460/3 "2017-08-20T16:24:30Z")

</div>

Hi Thiago,

I am using the following API,

curl -XPUT 'localhost:9200/sample?pretty' -H 'Content-Type: application/json' -d' { "settings" : { "index" : { "number\_of\_shards" : 3, "number\_of\_replicas" : 2 } } } '

---

<div class="post-metadata">

### Author: ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)
#### Post date: [August 20, 2017, 4:33pm UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460/4 "2017-08-20T16:33:25Z")

</div>

I understand what is the issue here. What you have created there is an actual index named "sample". But what you need to create is an [Index Template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html) so when you create any index that matches "sample-\*" it will use the settings from the template.

---

<div class="post-metadata">

### Author: ![rajesh](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@rajesh](https://discuss.elastic.co/u/rajesh)
#### Post date: [August 20, 2017, 6:58pm UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460/5 "2017-08-20T18:58:35Z")

</div>

Hi Thiago,

I think I will need to add number\_of\_replicas field to settings. I don't understand the purpose of mapping, properties, created at blocks. Can you please explain it?

---

<div class="post-metadata">

### Author: ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)
#### Post date: [August 20, 2017, 8:20pm UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460/6 "2017-08-20T20:20:45Z")

</div>

Defining a mapping manually is required when you want to fine-tune how Elasticsearch process documents. It is all explained [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html). But if you just starting with Elasticsearch, you don't need to worry about it, as Elasticsearch can automatically autodetect the mapping when new documents are indexed.

---

<div class="post-metadata">

### Author: ![rajesh](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@rajesh](https://discuss.elastic.co/u/rajesh)
#### Post date: [August 20, 2017, 9:50pm UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460/7 "2017-08-20T21:50:27Z")

</div>

But at this point I am not using "Type" concept for indexing. So, am I still good to use Index template API? And can you also let me know the advantage of using Type/Mapping? Once elasticsearch has good amount of documents then I will need to use Type concept?

---

<div class="post-metadata">

### Author: ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)
#### Post date: [August 20, 2017, 10:14pm UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460/8 "2017-08-20T22:14:42Z")

</div>

This is not really because of Type (types will be deprecated anyway). You need an index template so every time you create a "sample-\*" index then the same settings will be reused.

Your initial problem was that you created 2 indices: an index named "sample" and another one following "sample-%{+YYYY.MM.dd}". That's not how it works, to be able to reuse the settings that you have used when creating "sample" index you need to create an Index Template.

For fully understanding how this works I recommend that you attend the [Elastic Stack: Logging eLearning](https://training.elastic.co/elearning/elastic-stack-logging-on-demand) online course

---

<div class="post-metadata">

### Author: ![rajesh](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@rajesh](https://discuss.elastic.co/u/rajesh)
#### Post date: [August 20, 2017, 10:17pm UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460/9 "2017-08-20T22:17:43Z")

</div>

Thiago,

Thanks for the complete information 🙂

---

<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: [September 17, 2017, 10:17pm UTC](https://discuss.elastic.co/t/how-many-primary-and-replica-shards-will-be-allotted-for-a-dynamic-elasticsearch-index-ex-index-sample-yyyy-mm-dd/97460/10 "2017-09-17T22:17:44Z")

</div>

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