ES modify index settings
Modifying ES index settings #
To set index specific settings on ES you have three variants. You can modify settings:
- On existing index
- For all future indices
- On index creation
In the examples below we are setting number_of_replicas
. However, this is just an example. There are numerous other settings that you can set on the index level.
On existing index #
On the host localhost:9200
we will set number_of_replicas
to 0
for index named my-index-name
:
curl -X PUT "http://localhost:9200/my-index-name?pretty" -H 'Content-Type: application/json' -d'
{
"settings": {
"number_of_replicas": 0
}
}
'
Or a more compact way:
curl -X PUT "http://localhost:9200/my-index-name/_settings" -H 'Content-Type: application/json' -d'{ "number_of_replicas": 0 }'
In case you want to do it for all indices, you can first fetch them and then execute for each like:
$urls = curl -X GET "http://localhost:9200/_cat/indices?h=index"
foreach ($url in $urls) {
curl -X PUT "http://localhost:9200/$url/_settings" -H 'Content-Type: application/json' -d'{ "number_of_replicas": 0 }'
}
For future indices #
Then we will set template for all future indices whose name starts with index-name_
:
curl -X PUT "http://localhost:9200/_index_template/my_template_name?pretty" -H 'Content-Type: application/json' -d'
{
"index_patterns": ["index-name_*"],
"template": {
"settings": {
"number_of_replicas": 0
}
},
"priority": 500
}
'
To delete (remove) index template #
curl -X DELETE "http://localhost:9200/_index_template/my_template_name?pretty"
On index creation #
At the time of creating index you can specify settings object in the body of the request.
curl -X PUT "http://localhost:9200/test?pretty" -H 'Content-Type: application/json' -d'
{
"settings": {
"number_of_replicas": 0
},
"mappings": {
"properties": {
...
}
}
}
'
- Previous: VSCode Shortcuts
- Next: Domain basics