Hi, I am new with elasticsearch and I need to change the number of shards and index frequency of an existing index. Is there any way on how to change the shards and index frequency of an existing index without creating a new index? I need to (increase/decrease) the number of shards and replicas of an existing index. Currently, we are using rolling index which creates new index per day. Also we are using one template for all index pattern. Thank you and hoping for your help
Hello, I already tried this curl command for setting the shards for rolling index. And it showed that the set shards was changed into 1 but when I query the index, the number of shards sets again to default which is 5.
curl -XPUT 'local-host/_template/template1' -H 'Content-Type: application/json' -d'
{
"template" : "template1",
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
}
}
}'
Any help? Thank you.
I had the same issue for some time. What doesn't seem to be mentioned anywhere in the documentation I found is that your output index name needs to match the template name. For example, in a Logstash output, if you have the following:
output {
if [type] == "httplog" {
elasticsearch {
index => "httplog-%{+YYYY.MM.dd}"
hosts => ["es-01.myserver:9200"]
template_name => "httplog"
}
}
You would need a matching template in ES or a catch-all template. So, if you wanted a specific one you would execute:
curl -XPUT 'es-01.myserver.com:9200/_template/httplog?pretty' -H 'Content-Type: application/json' -d'
{
"index_patterns" : ["httplog-*"],
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 2,
"refresh_interval" : "5s"
}
}
'
Or, if you wanted to just have all indexes default to the above shard settings, you would run:
curl -XPUT 'es-01.myserver.com:9200/_template/Default?pretty' -H 'Content-Type: application/json' -d'
{
"index_patterns" : ["*"],
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 2,
"refresh_interval" : "5s"
}
}
'
Hope that helps.
Thank you. I've already changed the number of shards yesterday. And then I checked it again for today new logs, the shards of the new index was back to default again. Is there any way to change it also for the new incoming log indexes that it won't back to default size of shards?
Yesterday
Today
Any help? Thanks a lot!
first,my english is not very good. maybe I can't understand your problem accurately。
i think you need modify the “/home/es/elasticsearch-X.X.X/config/elasticsearch.yml” file after you creates new index per day before startup the elasticsearch service every time. change "index.number_of_shards" like this index.number_of_shards: 1
Hello, Thank you but we can't see the elasticsearch.yml because we are using the Amazon Elasticsearch. So we preferred using the curl command in setting and changing the shards. My problem was I've set the shards count into 1 and it doesn't apply to all indices from template1 using this curl command:
curl -XPUT 'local-host/_template/template1' -H 'Content-Type: application/json' -d'
{
"template" : "template1-*",
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
}
}
}'
This is my reference:
We have rolling index. The scenario was the shards for index template1-2018.02.27 was already set in to 1 because I've used the curl command above. The next day for the index template1-2018.02.28 it was back again to default size (5) of shards. I need to automate applying settings of 1 shards to all new indices whose name matches the template1.
Any thoughts/help? Thank you.
No this is a deprecated and now removed settings in earlier versions.
The way to go is by using index templates.
You need to look at all the templates you have.
May be share with us.
Please don't post images of text as they are hardly readable and not searchable.
Instead paste the text and format it with </>
icon. Check the preview window.
BTW did you check what cloud.elastic.co?
I've tried this example configuration:
PUT _template/token
{
"index_patterns": ["token-*"],
"settings": {
"number_of_shards": 1
}
}
And I got this error:
{
"error": {
"root_cause": [
{
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: template is missing;"
}
],
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: template is missing;"
},
"status": 400
}
Please format your code, logs or configuration files using </>
icon as explained in this guide and not the citation button. It will make your post more readable.
Or use markdown style like:
```
CODE
```
There's a live preview panel for exactly this reasons.
Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.
Which elasticsearch version is it?
Sorry for that one. I'm still learning how to use these also. I've edited it already. Currently, we are using elasticsearch version 5.5.2.
This is how how define an index template in older versions (ie 5.5): https://www.elastic.co/guide/en/elasticsearch/reference/5.5/indices-templates.html
Thank you. But I think the problem why the shards can't be modified is because the commands is not supported in earlier versions of Elasticsearch. We upgraded to 6.0.1 and it's already working. This command is working properly in 6.0.1.
PUT /_template/temp1
{
"order": 1,
"index_patterns": ["temp1-*"],
"settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 1
}
}
But I think the problem why the shards can't be modified is because the commands is not supported in earlier versions of Elasticsearch.
Not really. It's just that syntax changed.
BTW just to be clear, you are not changing index settings but index template settings.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.