Elasticsearch lets us tune itself by specifying the various parameters in the elasticsearch.yml
file. But you should treat this file as the set of default values that can be changed in the runtime using the Elasticsearch REST API. We can change both the per index setting and the cluster wide settings. However, you should remember that not all properties can be dynamically changed. If you try to alter these parameters, Elasticsearch will respond with a proper error.
In order to set one of the cluster properties, we need to use the HTTP PUT
method and send a proper request to the _cluster/settings
URI. However, we have two options: adding the changes as transient or permanent.
The first one, transient, will set the property only until the first restart. In order to do this, we send the following command:
curl -XPUT 'localhost:9200/_cluster/settings' -d '{ "transient" : { "PROPERTY_NAME" : "PROPERTY_VALUE" } }'
As you can see, in the preceding command, we used the object named transient and we added our property definition there. This means that the property will be valid only until the restart. If we want our property settings to persist between restarts, instead of using the object named transient
, we use the one named persistent
.
At any moment, you can fetch these settings using the following command:
curl -XGET localhost:9200/_cluster/settings
To change the indices related settings, Elasticsearch provides the /_settings
endpoint for changing the parameters for all the indices and the /index_name/_settings
endpoint for modifying the settings of a single index. When compared to the cluster wide settings, all the changes done to indices using the API are always persistent and valid after Elasticsearch restarts. To change the settings for all the indices, we send the following command:
curl -XPUT 'localhost:9200/_settings' -d '{ "index" : { "PROPERTY_NAME" : "PROPERTY_VALUE" } }'
The current settings for all the indices can be listed using the following command:
curl -XGET localhost:9200/_settings
To set a property for a single index, we run the following command:
curl -XPUT 'localhost:9200/index_name/_settings' -d '{ "index" : { "PROPERTY_NAME" : "PROPERTY_VALUE" } }'
The get the settings for the library
index, we run the following command:
curl -XGET localhost:9200/library/_settings