Nest Client c# 7.0 for elastic search removing Aliases

混江龙づ霸主 提交于 2020-05-15 21:44:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!