Update elasticsearch index mapping through script or curl command

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);
}
"""
}
}
}

Does that not work? What is the error?

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

Why does it needs to be a cron job?

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.

Ok, well then you are better off using an index template - Index templates | Elasticsearch Guide [7.15] | Elastic

we will use that by exploring index template.

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

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

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

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