ORTA
ES|QL (Elasticsearch Query Language)
ES 9.x ile gelen yeni SQL-benzeri sorgu dili. Pipe ( | ) operatörüyle zincirleme işlemler yapar. Öğrenme eğrisi düşük, güçlü analitik yetenekler.
Kod örneği tercihiBu sayfadaki istemci örneklerini birlikte değiştirir.
ES 9.x ile gelen yeni SQL-benzeri sorgu dili. Pipe (|) operatörüyle zincirleme işlemler yapar. Öğrenme eğrisi düşük, güçlü analitik yetenekler.
Karar Rehberi
| Durum | Öneri | Örnek veya gerekçe |
|---|---|---|
| Ad-hoc log analizi | Uygun: Hızlı pipe sorgu | Kibana Discover'da hata debug |
| Basit aggregation | Uygun: STATS...BY yeterli | Kategori bazlı özet rapor |
| Kompleks scoring/ranking | Uygun değil: function_score yok | Ürün arama relevance |
| Nested aggregation | Uygun değil: Pipeline agg desteği sınırlı | Multi-level drill-down |
| Hızlı prototipleme | Uygun: SQL bilen herkes yazabilir | Analyst exploration |
| Production API endpoint | Uygun değil: Query DSL daha stabil/optimize | High-traffic arama servisi |
| Time-series analiz | Uygun: DATE_TRUNC, BUCKET | Metrik dashboard |
# Temel ES|QL sorgusu
curl -X POST "http://localhost:9200/_query" -H "Content-Type: application/json" -d'
{
"query": "FROM products | WHERE price > 1000 AND is_active == true | STATS avg_price = AVG(price), count = COUNT(*) BY category | SORT avg_price DESC | LIMIT 10"
}'
# Zaman serisi analizi
curl -X POST "http://localhost:9200/_query" -H "Content-Type: application/json" -d'
{
"query": "FROM logs-* | WHERE @timestamp > NOW() - 1 hour | STATS error_count = COUNT(*) BY host, status_code | WHERE error_count > 100 | SORT error_count DESC"
}'
# Full-text search in ES|QL
curl -X POST "http://localhost:9200/_query" -H "Content-Type: application/json" -d'
{
"query": "FROM products | WHERE MATCH(description, "spor ayakkabı") | KEEP name, price, category, _score | SORT _score DESC | LIMIT 20"
}'
// ES|QL with .NET client
public async Task<List<CategoryReport>> GetCategoryReportAsync()
{
var response = await _client.Esql.QueryAsync(q => q
.Query("FROM products | WHERE is_active == true | STATS avg_price = AVG(price), total = COUNT(*), total_stock = SUM(stock) BY category | SORT total DESC | LIMIT 20")
.Format("json"));
// Parse response columns and values
return response.Columns.Any()
? ParseEsqlResponse<CategoryReport>(response)
: new List<CategoryReport>();
}
ES|QL vs Query DSL
| Özellik | ES|QL | Query DSL |
|---|---|---|
| Sözdizimi | SQL-like, pipe | JSON nested |
| Öğrenme | Kolay (SQL bilen için) | Orta-zor |
| Aggregations | STATS, EVAL | Aggs API (daha güçlü) |
| Full-text | MATCH() fonksiyonu | match, multi_match |
| Scripting | EVAL ile inline | Painless |
| Kibana | Discover, Lens | Dev Tools |
| Best for | Ad-hoc analiz, log sorgu | Production API, kompleks ranking |
Örnek: Bir DevOps ekibi Kibana Discover'da ES|QL kullanarak: FROM logs-* | WHERE status >= 500 AND @timestamp > NOW() - 15m | STATS count BY service, endpoint | SORT count DESC — anlık hata spike'ını saniyeler içinde bulur.