# A script to create many indices at the same time

**URL:** <https://discuss.elastic.co/t/a-script-to-create-many-indices-at-the-same-time/166726>\
**Category:** Elasticsearch\
**Created:** [February 1, 2019, 12:01pm UTC](https://discuss.elastic.co/t/a-script-to-create-many-indices-at-the-same-time/166726 "2019-02-01T12:01:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Askia\_Mohamed\_Kadri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/askia_mohamed_kadri/32/134665_2.png) [@Askia\_Mohamed\_Kadri](https://discuss.elastic.co/u/Askia_Mohamed_Kadri)\
**Post date:** [February 1, 2019, 12:01pm UTC](https://discuss.elastic.co/t/a-script-to-create-many-indices-at-the-same-time/166726/1 "2019-02-01T12:01:07Z")

</div>

Hi! Please I would like to create many indices at the same time with a defined pattern. Does anybody know a scipt or has a solution to do that.

Thanks

---

<div class="post-metadata">

**Author:** ![Askia\_Mohamed\_Kadri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/askia_mohamed_kadri/32/134665_2.png) [@Askia\_Mohamed\_Kadri](https://discuss.elastic.co/u/Askia_Mohamed_Kadri)\
**Post date:** [February 1, 2019, 2:48pm UTC](https://discuss.elastic.co/t/a-script-to-create-many-indices-at-the-same-time/166726/2 "2019-02-01T14:48:01Z")

</div>

I finally found it myself. For those interested... Here are two scripts in batch  
1- gets all the indices names from elasticsearch and stores them in a file  
curl -HContent-Type:application/json -XGET localhost:9200/\_cat/indices/?h=index\>indices.txt

2- Creates new indices name-based on the existing indices  
for /f "tokens=\*" %%a in (indices.txt) do (  
curl -HContent-Type:application/json -XPUT localhost:9200/"%%a-new\_one"  
)

And this is the hole script in bash (that I didn't tested):

#!/bin/bash

liste\_indexs=`curl -HContent-Type:application/json -XGET localhost:9200/_cat/indices \> indices.txt`

for index in $liste\_indexs; do  
curl -HContent-Type:application/json -XPUT localhost:9200/"$index-new\_one"  
done

---

<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:** [March 1, 2019, 2:48pm UTC](https://discuss.elastic.co/t/a-script-to-create-many-indices-at-the-same-time/166726/3 "2019-03-01T14:48:13Z")

</div>

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