-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Listing all indices of an alias
Oliver Eilhard edited this page Feb 13, 2018
·
3 revisions
Aliases are a nice feature of Elasticsearch to give a set of indices a unique name, the alias. Operations on the alias are automatically executed on all indices of that alias. Indices can also be atomically added and removed from the alias. So aliases give you a lot of freedom to implement interesting features, e.g. for time-based data.
Use the following snippet to list all indices of an alias.
// IndexNamesByAlias returns a list of index names that are
// associated by the given aliasName.
func IndexNamesByAlias(aliasName string) ([]string, error) {
res, err := client.Aliases().Index("_all").Do(context.Background())
if err != nil {
return nil, err
}
return res.IndicesByAlias(aliasName), nil
}