ElasticSearch Nest 跨集群搜索 C#

ElasticSearch Nest Cross-Cluster Search C#

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

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

也找不到关于它的文档。

如有任何帮助,我们将不胜感激。

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" 的索引