diff --git a/salt/elasticsearch/template.map.jinja b/salt/elasticsearch/template.map.jinja index 904ab862c..659823df8 100644 --- a/salt/elasticsearch/template.map.jinja +++ b/salt/elasticsearch/template.map.jinja @@ -64,88 +64,51 @@ {# advanced ilm actions #} {% if settings.policy is defined and settings.policy.phases is defined %} -{# start HOT actions #} -{# only run if hot action is defined for this index #} -{% if settings.policy.phases.hot is defined and settings.policy.phases.hot.actions is defined %} -{% set HA = settings.policy.phases.hot.actions %} -{% if HA.shrink is defined %} -{% if HA.shrink.method is defined %} -{% if HA.shrink.method == 'COUNT' and HA.shrink.number_of_shards is defined and HA.shrink.number_of_shards %} -{# remove max_primary_shard_size value when doing shrink operation by count vs size #} -{% do HA.shrink.pop('max_primary_shard_size', none) %} -{% elif HA.shrink.method == 'SIZE' and HA.shrink.max_primary_shard_size is defined and HA.shrink.max_primary_shard_size %} -{# remove number_of_shards value when doing shrink operation by size vs count #} -{% do HA.shrink.pop('number_of_shards', none) %} -{% else %} -{# method isn't defined or missing a required config number_of_shards/max_primary_shard_size #} -{% do HA.pop('shrink', none) %} +{% set PHASE_NAMES = ["hot", "warm", "cold"] %} +{% for P in PHASE_NAMES %} +{% if settings.policy.phases[P] is defined and settings.policy.phases[P].actions is defined %} +{% set PHASE = settings.policy.phases[P].actions %} +{# remove allocate action if number_of_replicas isn't configured #} +{% if PHASE.allocate is defined %} +{% if PHASE.allocate.number_of_replicas is defined and not PHASE.allocate.number_of_replicas %} +{% do PHASE.pop('allocate', none) %} {% endif %} {% endif %} -{% endif %} -{# always remove method since its only used for SOC config, not in the actual ilm policy #} -{% if HA.shrink is defined %} -{% do HA.shrink.pop('method', none) %} -{% endif %} -{# end shrink action #} -{# start force merge #} -{% if HA.forcemerge is defined %} -{% if HA.forcemerge.index_codec is defined and HA.forcemerge.index_codec %} -{% do HA.forcemerge.update({'index_codec': 'best_compression'}) %} -{% else %} -{% do HA.forcemerge.pop('index_codec', none) %} -{% endif %} -{% if HA.forcemerge.max_num_segments is defined and not HA.forcemerge.max_num_segments %} -{# max_num_segments is empty, drop it #} -{% do HA.pop('forcemerge', none) %} -{% endif %} -{% endif %} -{# end force merge #} -{% endif %} -{# end HOT actions #} -{# Start WARM actions #} -{# only run if warm action is defined for this index #} -{% if settings.policy.phases.warm is defined and settings.policy.phases.warm.actions is defined %} -{% set WA = settings.policy.phases.warm.actions %} -{# start warm shrink action #} -{% if WA.shrink is defined %} -{% if WA.shrink.method is defined %} -{% if WA.shrink.method == 'COUNT' and WA.shrink.number_of_shards is defined and WA.shrink.number_of_shards %} -{# remove max_primary_shard_size value when doing shrink operation by count vs size #} -{% do WA.shrink.pop('max_primary_shard_size', none) %} -{% elif WA.shrink.method == 'SIZE' and WA.shrink.max_primary_shard_size is defined and WA.shrink.max_primary_shard_size %} -{# remove number_of_shards value when doing shrink operation by size vs count #} -{% do WA.shrink.pop('number_of_shards', none) %} -{% else %} -{# method isn't defined or missing a required config number_of_shards/max_primary_shard_size #} -{% do WA.pop('shrink', none) %} +{# start shrink action #} +{% if PHASE.shrink is defined %} +{% if PHASE.shrink.method is defined %} +{% if PHASE.shrink.method == 'COUNT' and PHASE.shrink.number_of_shards is defined and PHASE.shrink.number_of_shards %} +{# remove max_primary_shard_size value when doing shrink operation by count vs size #} +{% do PHASE.shrink.pop('max_primary_shard_size', none) %} +{% elif PHASE.shrink.method == 'SIZE' and PHASE.shrink.max_primary_shard_size is defined and PHASE.shrink.max_primary_shard_size %} +{# remove number_of_shards value when doing shrink operation by size vs count #} +{% do PHASE.shrink.pop('number_of_shards', none) %} +{% else %} +{# method isn't defined or missing a required config number_of_shards/max_primary_shard_size #} +{% do PHASE.pop('shrink', none) %} +{% endif %} {% endif %} {% endif %} -{% endif %} -{# always remove method since its only used for SOC config, not in the actual ilm policy #} -{% if WA.shrink is defined %} -{% do WA.shrink.pop('method', none) %} -{% endif %} -{# end shrink action #} -{# start force merge #} -{% if WA.forcemerge is defined %} -{% if WA.forcemerge.index_codec is defined and WA.forcemerge.index_codec %} -{% do WA.forcemerge.update({'index_codec': 'best_compression'}) %} -{% else %} -{% do WA.forcemerge.pop('index_codec', none) %} +{# always remove shrink method since its only used for SOC config, not in the actual ilm policy #} +{% if PHASE.shrink is defined %} +{% do PHASE.shrink.pop('method', none) %} {% endif %} -{% if WA.forcemerge.max_num_segments is defined and not WA.forcemerge.max_num_segments %} -{# max_num_segments is empty, drop it #} -{% do WA.pop('forcemerge', none) %} +{# end shrink action #} +{# start force merge #} +{% if PHASE.forcemerge is defined %} +{% if PHASE.forcemerge.index_codec is defined and PHASE.forcemerge.index_codec %} +{% do PHASE.forcemerge.update({'index_codec': 'best_compression'}) %} +{% else %} +{% do PHASE.forcemerge.pop('index_codec', none) %} +{% endif %} +{% if PHASE.forcemerge.max_num_segments is defined and not PHASE.forcemerge.max_num_segments %} +{# max_num_segments is empty, drop it #} +{% do PHASE.pop('forcemerge', none) %} +{% endif %} {% endif %} +{# end force merge #} {% endif %} -{# end force merge #} -{% if WA.allocate is defined %} -{% if WA.allocate.number_of_replicas is defined and not WA.allocate.number_of_replicas %} -{% do WA.pop('allocate', none) %} -{% endif %} -{% endif %} -{% endif %} -{# end WARM actions #} +{% endfor %} {% endif %} {% do ES_INDEX_SETTINGS.update({index | replace("_x_", "."): ES_INDEX_SETTINGS_GLOBAL_OVERRIDES[index]}) %}