EElasticsearch Handbook

İLERİ

Performans Optimizasyonu

ES performansı indexing throughput, search latency ve resource utilization üçgeninde dengelenir.

Kod örneği tercihiBu sayfadaki istemci örneklerini birlikte değiştirir.

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

Indexing Speed refresh=-1, replica=0 Search Latency filter cache, routing Resource Usage heap, disk, CPU Balance Tradeoff Indexing ↑ • Bulk API • refresh_interval=-1 • replica=0 • Translog async Latency ↓ • Filter context • Custom routing • _source filter • Request cache

Karar Rehberi

DurumÖneriÖrnek veya gerekçe
refresh_interval=-1 Uygun: Initial bulk load Gece ETL batch
Filter context Uygun: Exact match, score gereksiz Kategori filtresi
Custom routing Uygun: Multi-tenant, known partition key Tenant isolation
_source filtering Uygun: Büyük dokümanlar (>5KB) Sadece name+price dön
Force merge Uygun: Read-only index (ILM warm) Log archive
Searchable snapshot Uygun: Cold data, nadir erişim 90+ gün log

İndexing Performansı

Teknik Etki Ne Zaman
Bulk API 10-50x hız Her zaman (>100 doc)
refresh_interval: -1 2-5x hız Initial load
replica: 0 2x hız Initial load
Translog flush 10-20% hız Yüksek throughput
Pipeline disable Değişken Ingest gereksizse

Search Performansı

Teknik Etki Ne Zaman
Filter context 2-10x hız Score gereksizse
_source filtering 20-40% hız Büyük dokümanlar
routing N/shard_count hız Tenant-based
request_cache Cache hit = instant Tekrarlayan agg
Profile API Diagnoz Yavaş sorgular
# Slow log aktifleştirme
curl -X PUT "http://localhost:9200/products/_settings" -H "Content-Type: application/json" -d'
{
  "index.search.slowlog.threshold.query.warn": "5s",
  "index.search.slowlog.threshold.query.info": "2s",
  "index.search.slowlog.threshold.fetch.warn": "1s",
  "index.indexing.slowlog.threshold.index.warn": "10s"
}'

# Search profiling
curl -X GET "http://localhost:9200/products/_search" -H "Content-Type: application/json" -d'
{
  "profile": true,
  "query": { "match": { "description": "spor ayakkabı" } }
}'

# Custom routing (tenant isolation)
curl -X POST "http://localhost:9200/orders/_doc?routing=tenant_123" -H "Content-Type: application/json" -d'
{
  "tenant_id": "tenant_123",
  "product": "Nike Air",
  "amount": 1500
}'

# Search with routing (sadece ilgili shard'a git)
curl -X GET "http://localhost:9200/orders/_search?routing=tenant_123" -H "Content-Type: application/json" -d'
{
  "query": { "term": { "tenant_id": "tenant_123" } }
}'
// Routing-based multi-tenant search
public async Task<List<Order>> GetTenantOrdersAsync(string tenantId)
{
    var response = await _client.SearchAsync<Order>(s => s
        .Index("orders")
        .Routing(tenantId)  // Sadece ilgili shard'a git
        .Query(q => q.Term(t => t.Field(f => f.TenantId).Value(tenantId)))
        .Size(100)
        .SourceIncludes(new[] { "product", "amount", "order_date" }));

    return response.Documents.ToList();
}

// Search with profiling
public async Task<string> ProfileSearchAsync(string query)
{
    var response = await _client.SearchAsync<Product>(s => s
        .Index("products")
        .Profile(true)
        .Query(q => q.Match(m => m.Field(f => f.Description).Query(query))));

    return response.Profile?.ToString() ?? "No profile data";
}

Örnek: Multi-tenant SaaS'ta routing ile her tenant'ın verisi tek shard'da tutulur. 50-shard cluster'da routing OLMADAN arama 50 shard'ı tarar, routing ile sadece 1 shard — 50x daha az IO.