问题
So with the latest update with Elastic Search 6, The C# Client was also upgraded too. But i can't figure out how to write this code the new way with the new Client Nest 7. I just need to rewrite this code
var indexExists = Client.IndexExists(CurrentAliasName).Exists;
Client.Alias(aliases => {
if (indexExists)
{
var oldIndices = Client.GetIndicesPointingToAlias(CurrentAliasName);
var indexName = oldIndices.First().ToString();
//remove alias from live index
aliases.Remove(a => a.Alias(CurrentAliasName).Index("*"));
}
return aliases.Add(a => a.Alias(CurrentAliasName).Index(CurrentIndexName));
});
回答1:
The APIs have been moved into API groupings
var client = new ElasticClient();
var CurrentAliasName = "alias_name";
var CurrentIndexName = "index_name";
var indexExists = client.Indices.Exists(CurrentAliasName).Exists;
client.Indices.BulkAlias(aliases =>
{
if (indexExists)
{
var oldIndices = client.GetIndicesPointingToAlias(CurrentAliasName);
var indexName = oldIndices.First().ToString();
//remove alias from live index
aliases.Remove(a => a.Alias(CurrentAliasName).Index("*"));
}
return aliases.Add(a => a.Alias(CurrentAliasName).Index(CurrentIndexName));
});
You can also reference Nest.7xUpgradeAssistant package and keep using the same methods as in 6.x to help with the move to 7.x. You'll get compiler warnings with messages to indicate where the new API methods are located.
来源:https://stackoverflow.com/questions/58291005/nest-client-c-sharp-7-0-for-elastic-search-removing-aliases