def switch_read_index(new_name)
      new_index = [config.read_alias, new_name].join('_')

      old_index =
        if client.indices.exists_alias?(name: config.read_alias)
          client.indices.get_alias(name: config.read_alias).keys.first
        end

      remove_action =
        ({ remove: { index: old_index, alias: config.read_alias } } if old_index)

      client.indices.update_aliases(body: {
                                      actions: [
                                        remove_action,
                                        { add: { index: new_index, alias: config.read_alias } }
                                      ].compact
                                    })
    end
def switch_read_index(new_name)
      new_index = [config.read_alias, new_name].join('_')

      old_index =
        if client.indices.exists_alias?(name: config.read_alias)
          client.indices.get_alias(name: config.read_alias).keys.first
        end

      remove_action =
        ({ remove: { index: old_index, alias: config.read_alias } } if old_index)

      client.indices.update_aliases(body: {
                                      actions: [
                                        remove_action,
                                        { add: { index: new_index, alias: config.read_alias } }
                                      ].compact
                                    })
    end
rubocop:disable Metrics/AbcSize