【问题标题】:ElasticSearch Nest Cross-Cluster Search C#ElasticSearch Nest 跨集群搜索 C#
【发布时间】:2021-05-12 09:07:49
【问题描述】:

我需要使用 Nest 执行跨集群搜索,但我找不到方法。

Uri elasticNode = new Uri(elasticSearchUri); ConnectionSettings nodeSettings = new ConnectionSettings(elasticNode).DefaultIndex(elasticIndexName); ElasticClient elasticClient = new ElasticClient(nodeSettings);

也找不到关于它的文档。

任何帮助将不胜感激。

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    search across clusters,首先需要配置至少一个远程集群

    var pool = new SingleNodeConnectionPool(new Uri("http://example.com:9200"));
    var settings = new ConnectionSettings(pool);
    var client = new ElasticClient(settings);
    
    var putSettingsResponse = client.Cluster.PutSettings(s => s
        .Persistent(d => d
            .Add("cluster.remote.cluster_two.seeds", new[] { "127.0.0.1:9300" })
            .Add("cluster.remote.cluster_two.skip_unavailable", true)
        )
    );
    

    这会在127.0.0.1:9300 配置一个名为cluster_two 的集群(使用传输层端口)。

    现在,搜索配置了客户端的集群和远程集群

    var searchResponse = client.Search<MyDocument>(s => s
        .Index("index_name,cluster_two:index_name")
        .Query(q => q
            .MatchAll()
        )
    );
    

    http://example.com:9200 的集群中搜索名为"index_name" 的索引,在127.0.0.1 的远程集群中搜索名为"index_name" 的索引

    【讨论】:

    • 感谢您,在看到响应之前我最终能够做到这一点,但这是正确的,我最终使用了 .Index(*:index_name) 因为我运行了多个远程集群。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多