function switchAndRemoveAllAliases() {
  const actions = aliasNames.reduce((actions, alias) => {
    const newActions = [
      {
        add: { index: getIndexName(alias), alias },
      },
    ];
    const oldIndexName = aliasToOldIndexMap[alias];
    if (oldIndexName)
      newActions.push({
        remove_index: { index: oldIndexName },
      });

    return actions.concat(newActions);
  }, []);

  return client.indices.updateAliases({ body: { actions } });
}
/**
 * Switch alias to new index and remove old indexes in one go.
 *
 * Reference: https://www.elastic.co/guide/en/elasticsearch/reference/6.2/indices-aliases.html
 *
 * @returns {Promise<object>}
 */
Switch alias to new index and remove old indexes in one go.

@returns {Promise}
Switch alias to new index and remove old indexes in one go . @returns { Promise }
function switchAndRemoveAllAliases() {
  const actions = aliasNames.reduce((actions, alias) => {
    const newActions = [
      {
        add: { index: getIndexName(alias), alias },
      },
    ];
    const oldIndexName = aliasToOldIndexMap[alias];
    if (oldIndexName)
      newActions.push({
        remove_index: { index: oldIndexName },
      });
    return actions.concat(newActions);
  }, []);
  return client.indices.updateAliases({ body: { actions } });
}
function switchAndRemoveAllAliases ( ) { const actions = aliasNames . reduce ( ( actions , alias ) => { const newActions = [ { add : { index : getIndexName ( alias ) , alias } , } , ] ; const oldIndexName = aliasToOldIndexMap [ alias ] ; if ( oldIndexName ) newActions . push ( { remove_index : { index : oldIndexName } , } ) ; return actions . concat ( newActions ) ; } , [ ] ) ; return client . indices . updateAliases ( { body : { actions } } ) ; }
Switch alias to new index and remove old indexes in one go.
Switch alias to new index and remove old indexes in one go .