Nest Client c#7.0用于弹性搜索删除别名 [英] Nest Client c# 7.0 for elastic search removing Aliases

查看:109
本文介绍了Nest Client c#7.0用于弹性搜索删除别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,随着Elastic Search 6的最新更新,C#客户端也进行了升级.但是我不知道如何使用新的Client Nest 7以新的方式编写此代码.我只需要重写此代码

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));
        });

推荐答案

API已移入API分组

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));
});

您还可以引用 Nest.7xUpgradeAssistant 包,并继续使用与在6.x中帮助升级到7.x.您将收到带有消息的编译器警告,以指示新API方法的位置.

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.

这篇关于Nest Client c#7.0用于弹性搜索删除别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆