0
votes

I wrote some node script to create and populate an index in elastic search (https://github.com/tgirotto/Elasticsearch); however, now I want to be able to customise the index by defining the number of primary shards and replica shards. I looked it up in the elastic search javascript api docs, but didn't find anything. Any ideas?

1

1 Answers

1
votes

It is not possible to change the number of primary shards after having created an index. You can however change the number of replicas per primary shard.

http://www.elastic.co/guide/en/elasticsearch/guide/current/_index_settings.html

PUT /my_temp_index/_settings
{
    "number_of_replicas": 1
}

So you will have to carefully determine the number of primary shards you need before creating your index and then do something like this:

curl -XPUT 'http://localhost:9200/twitter/' -d '{
    "settings" : {
        "number_of_shards" : 3,
        "number_of_replicas" : 2
    }
}'

Edit: Excuse my reading skills... I thought you were asking for how to make changes after already creating an index, not how to set the shards/replicas beforehand.

Anyway, as you can see above, it is fairly easy to specify the number of replicas/shards. Please consult the definite guide on elasticsearch.org, such as:

http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html