Elasticsearch tip #2:

TL;DR: configure an index setting to null, to use the default

Quite often you might need to change an elasticsearch' index setting to something else than the default, e.g. to manually control the shard allocation process (allocating specific indices only on specific nodes):

# curl -XPUT localhost:9200/indexname/_settings -d '{ "index.routing.allocation.require._ip": "10.0.0.11,10.0.0.12" }'
{"acknowledged":true}

It's not clear how to go about resetting the setting (or, basically, removing it) (See updating index settings) There is a related feature, documented in Cluster Update Settings, which actually works for indices, too:

Resetting persistent or transient settings can be done by assigning a null value. If a transient setting is reset, the persistent setting is applied if available. Otherwise Elasticsearch will fallback to the setting defined at the configuration file or, if not existent, to the default value.

It turns out that the feature is indeed there, just not documented yet (see #22870). So, for example, to reset the allocation settings for the same index (see first example):

# curl -XPUT localhost:9200/indexname/_settings -d '{ "index.routing.allocation.require._ip": null }'
{"acknowledged":true}

Sidenote: this feature stopped working in ElasticSearch 5.4.0, because of an seemingly unrelated change that added an 'IP validator' for several index/cluster settings. I ran into it while upgrading from 5.0.2, and there is a fix for it in 5.4.1 already (I reported the bug to the ES team, see: #24709).

What would happen is:

# curl -XPUT localhost:9200/indexname/_settings -d '{ "index.routing.allocation.require._ip": null }'
{
 "error" : {
   "root_cause" : [
     {
       "type" : "null_pointer_exception",
       "reason" : null
     }
   ],
   "type" : "null_pointer_exception",
   "reason" : null
 },
 "status" : 500
}

Comments