Aliasing

edit

Adding/removing and updating aliases are also easy to do in NEST. For more information look at the Alias documentation

Add

edit

Fluent Syntax

edit
client.Alias(a => a
    .Add(add => add
        .Index("myindex")
        .Alias("myalias")
    )
);

Object Initializer Syntax

edit
var request = new AliasRequest
{
    Actions = new IAliasAction[]
    {
        new AliasAddAction
        {
            Add = new AliasAddOperation { Index = "myindex", Alias = "myalias" }
        }
    }
};

client.Alias(request);

Remove

edit

Fluent Syntax

edit
client.Alias(a => a
    .Remove(remove => remove
        .Index("myindex")
        .Alias("myalias")
    )
);

Object Initializer Syntax

edit
var request = new AliasRequest
{
    Actions = new IAliasAction[]
    {
        new AliasRemoveAction
        {
            Remove = new AliasRemoveOperation { Index = "myindex", Alias = "myalias" }
        }
    }
};

client.Alias(request);

Rename

edit

To rename an alias, just do an Add and a Remove in the same operation. Elasticsearch will then atomically rename your alias:

Fluent Syntax

edit
client.Alias(a => a
    .Add(add => add
        .Index("myindex")
        .Alias("newalias")
    )
    .Remove(remove => remove
        .Index("myindex")
        .Alias("oldalias")
    )
);

Object Initializer Syntax

edit
var request = new AliasRequest
{
    Actions = new IAliasAction[]
    {
        new AliasAddAction
        {
            Add = new AliasAddOperation { Index = "myindex", Alias = "myalias" }
        },
        new AliasRemoveAction
        {
            Remove = new AliasRemoveOperation { Index = "myindex", Alias = "myalias" }
        }
    }
};

client.Alias(request);