EElasticsearch Handbook

İLERİ

Cross-Cluster Search & Replication

Birden fazla cluster arasında federated search ve async replication.

Seviye: İleri+ — Bu bölüm production deneyimi gerektirir.

EU Cluster (Frankfurt) products Leader orders-eu logs-* users 3 master + 4 data nodes US Cluster (Virginia) products Follower (CCR) orders-us logs-* users 3 master + 4 data nodes Cross-Cluster Search eu_cluster:products,us_cluster:products Federated results + RRF merge Single API endpoint CCR: Async Replication (products leader→follower)

Karar Rehberi

DurumÖneriÖrnek veya gerekçe
Cross-Cluster Search (CCS) Uygun: Global arama, multi-region Global ürün arama
Cross-Cluster Replication (CCR) Uygun: DR, read replica, geo-proximity EU→US failover
Remote cluster (seed mode) Uygun: Küçük remote cluster 2-3 node remote
Remote cluster (proxy mode) Uygun: Büyük remote, single endpoint 50+ node remote
Auto-follow pattern Uygun: Otomatik yeni index replication logs-* auto-follow
Bi-directional replication Uygun: Active-active (farklı index'ler) EU: orders-eu, US: orders-us
REST API
# Remote cluster bağlantısı
curl -X PUT "http://localhost:9200/_cluster/settings" -H "Content-Type: application/json" -d'
{
  "persistent": {
    "cluster.remote.eu_cluster.seeds": ["eu-node1:9300", "eu-node2:9300"],
    "cluster.remote.us_cluster.seeds": ["us-node1:9300"]
  }
}'

# Cross-cluster search
curl -X GET "http://localhost:9200/local_index,eu_cluster:products,us_cluster:products/_search" -H "Content-Type: application/json" -d'
{
  "query": { "match": { "name": "Nike" } }
}'

# Cross-cluster replication (CCR) - follower index
curl -X PUT "http://localhost:9200/products-replica/_ccr/follow" -H "Content-Type: application/json" -d'
{
  "remote_cluster": "eu_cluster",
  "leader_index": "products"
}'
.NET Client
public class CrossClusterService
{
    private readonly ElasticsearchClient _client;

    public CrossClusterService(ElasticsearchClient client) => _client = client;

    // Cross-cluster search: query multiple clusters
    public async Task<List<Product>> GlobalSearchAsync(string query)
    {
        var response = await _client.SearchAsync<Product>(s => s
            .Index("local_products,eu_cluster:products,us_cluster:products")
            .Query(q => q.MultiMatch(mm => mm
                .Query(query)
                .Fields(new[] { "name^3", "description" })
                .Type(TextQueryType.BestFields)
                .Fuzziness(new Fuzziness("AUTO"))))
            .Size(20));
        return response.Documents.ToList();
    }

    // Check remote cluster connectivity
    public async Task<Dictionary<string, bool>> CheckRemoteClustersAsync()
    {
        var response = await _client.Cluster.RemoteInfoAsync();
        var result = new Dictionary<string, bool>();
        if (response.IsValidResponse)
        {
            foreach (var (name, info) in response)
                result[name] = info.Connected;
        }
        return result;
    }
}

Örnek: Global e-ticaret: EU cluster (Frankfurt) + US cluster (Virginia). Her bölge kendi ürünlerini yönetir, ama global arama cross-cluster search ile her iki cluster'ı sorgular. CCR ile critical index'ler pasif DR cluster'a replicate edilir.