# Update elasticsearch index mapping through script or curl command

**URL:** <https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905>\
**Category:** Elasticsearch\
**Created:** [October 17, 2021, 4:00am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905 "2021-10-17T04:00:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![prataprajasekhar](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@prataprajasekhar](https://discuss.elastic.co/u/prataprajasekhar)\
**Post date:** [October 17, 2021, 4:00am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905/1 "2021-10-17T04:00:04Z")

</div>

Dear Team,

We are trying to update an index using below method in kibana dev console.

Can you please let me know the method to be followed either using curl method or wget method or via a python or shell script to update ?

PUT index-xyz\*/\_mappings  
{  
"runtime": {  
"exception": {  
"type": "keyword",  
"script": """  
if(doc["stack\_trace.keyword"].size() \> 0){  
String response=doc["stack\_trace.keyword"].value;  
String exceptionClass = (response.indexOf(':') \> 0)?response.substring(0,response.indexOf(':')):"";  
emit(exceptionClass);  
}  
"""  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 18, 2021, 12:38am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905/2 "2021-10-18T00:38:26Z")

</div>

Does that not work? What is the error?

---

<div class="post-metadata">

**Author:** ![prataprajasekhar](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@prataprajasekhar](https://discuss.elastic.co/u/prataprajasekhar)\
**Post date:** [October 18, 2021, 1:09am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905/3 "2021-10-18T01:09:02Z")

</div>

Looking for executing this via cronjob or via any curl command.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 18, 2021, 1:29am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905/4 "2021-10-18T01:29:16Z")

</div>

Why does it needs to be a cron job?

---

<div class="post-metadata">

**Author:** ![prataprajasekhar](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@prataprajasekhar](https://discuss.elastic.co/u/prataprajasekhar)\
**Post date:** [October 18, 2021, 4:22am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905/5 "2021-10-18T04:22:26Z")

</div>

The new index gets created daily and wanted to change mapping as soon as new index is created.

Hence we need this mapping to be applied post few minutes of index creation.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 18, 2021, 4:24am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905/6 "2021-10-18T04:24:25Z")

</div>

Ok, well then you are better off using an index template - [Index templates | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/index-templates.html)

---

<div class="post-metadata">

**Author:** ![prataprajasekhar](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@prataprajasekhar](https://discuss.elastic.co/u/prataprajasekhar)\
**Post date:** [October 18, 2021, 4:26am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905/7 "2021-10-18T04:26:46Z")

</div>

we will use that by exploring index template.

For now can we have a solution to apply mapping change via script or curl command?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 18, 2021, 4:28am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905/8 "2021-10-18T04:28:15Z")

</div>

Anything else is up to you to maintain and manage, this is inbuilt technology so is the best solution.

---

<div class="post-metadata">

**Author:** ![prataprajasekhar](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@prataprajasekhar](https://discuss.elastic.co/u/prataprajasekhar)\
**Post date:** [October 18, 2021, 4:30am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905/9 "2021-10-18T04:30:40Z")

</div>

cool.

Can you please help suggesting the method for implementing this solution at index template level?

or share any steps for acheiving this through index template

---

<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 15, 2021, 4:31am UTC](https://discuss.elastic.co/t/update-elasticsearch-index-mapping-through-script-or-curl-command/286905/10 "2021-11-15T04:31:03Z")

</div>

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