Index settings are more important because they allow you to control several important Elasticsearch functionalities such as sharding/replica, caching, term management, routing, and analysis.
You need an up-and-running Elasticsearch installation, as used in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To execute curl
via the command line, you need to install curl
for your operative system.
To correctly execute the following commands, use the index created in the Creating an index recipe.
For managing the index settings, we will perform the following steps:
http://<server>/<index_name>/_settings
GET
and an example of call, using the index created in the Creating an index recipe, is as follows:curl -XGET 'http://localhost:9200/myindex/_settings? pretty=true'
{ "myindex" : { "settings" : { "index" : { "uuid" : "pT65_cn_RHKmg1wPX7BGjw", "number_of_replicas" : "1", "number_of_shards" : "2", "version" : { "created" : "1020099" } } } } }
1
), shards (2
), and the index creation version (1020099
). The UUID represents the unique ID of the index.PUT
method. A typical settings change is to increase the replica number:curl -XPUT 'http://localhost:9200/myindex/_settings' -d ' {"index":{ "number_of_replicas": "2"}}'
Elasticsearch provides a lot of options to tune the index behaviors, such as:
index.number_of_replicas
: The number of replicas each shard hasindex.auto_expand_replicas
: This allows you to define a dynamic number of replicas related to the number of shardsindex.refresh_interval
control the rate of automatic refresh.index.blocks
settings.index.routing.allocation.*
namespace.There are other index settings that can be configured for very specific needs. In every new version of Elasticsearch, the community extends these settings to cover new scenarios and requirements.
The refresh_interval
parameter allows several tricks to optimize the indexing speed. It controls the rate of refresh and refreshing and reduces the index performances due to opening and closing of files. A good practice is to disable the refresh interval (set -1) during a big bulk indexing and restore the default behavior after it. This can be done with these steps:
curl -XPOST 'http://localhost:9200/myindex/_settings' -d ' {"index":{"index_refresh_interval": "-1"}}'
curl -XPOST 'http://localhost:9200/myindex/_settings' -d ' {"index":{"index_refresh_interval": "1s"}}'
curl -XPOST 'http://localhost:9200/myindex/_optimize'
3.21.43.26