← Kursa Dön
📄 Text · 30 min

İlk Adımlar — REST API ve Kibana Dev Tools

REST API, cURL, Kibana Dev Tools ile Tanışma

Araba kullanmayı öğrenirken ilk yapılan şey nedir? Motor teorisi değil — direksiyonu tutmak, vitesi kavramak, gaza yavaşça basmak. Elasticsearch da öyle. Kurulumu yaptık, şimdi direksiyona geçiyoruz.

Bu derste Elasticsearch ile "konuşmayı" öğreneceksin. Her komutu, her yanıtı anlayacaksın. Ders sonunda Elasticsearch'e veri ekleyip, arayıp, silebileceksin.


Elasticsearch REST API'si

Elasticsearch ile tüm iletişim HTTP REST API üzerinden gerçekleşir. Bu şu anlama gelir:

  • Her işlem bir HTTP isteği (request)

  • Her yanıt bir JSON dökümanı (response)

  • Standart HTTP metotları kullanılır: GET, POST, PUT, DELETE

  • Herhangi bir programlama dilinden, herhangi bir HTTP client ile erişilebilir

API Yapısı

HTTP_METHOD  /index/_endpoint
             ─────  ─────────
               │        │
               │        └── Ne yapacağız? (_search, _doc, _mapping...)
               └────────── Hangi index üzerinde?

Örnekler:

GET    /products/_search       → products index'inde ara
POST   /products/_doc          → products index'ine döküman ekle
PUT    /products/_doc/1        → products index'inde ID=1 dökümanı oluştur/güncelle
DELETE /products/_doc/1        → products index'inde ID=1 dökümanı sil
GET    /_cluster/health        → Cluster sağlık durumu (index belirtmeye gerek yok)
GET    /_cat/indices?v         → Tüm index'leri listele

HTTP Metotları ve Anlamları

HTTP MetoduElasticsearch'te AnlamıÖrnek
GETVeri oku, arama yapGET /products/_doc/1
POSTVeri oluştur, arama yapPOST /products/_doc
PUTVeri oluştur/güncelle, ayar yapPUT /products/_doc/1
DELETEVeri silDELETE /products/_doc/1
HEADVarlık kontrolü (body yok)HEAD /products/_doc/1

💡 İpucu: GET ile de arama yapabilirsin, POST ile de. Elasticsearch ikisini de kabul eder. POST body'si büyük sorgularda tercih edilir çünkü bazı HTTP client'ları GET request'e body eklemeye izin vermez.


cURL ile Elasticsearch

cURL, komut satırından HTTP isteği göndermenin en temel yolu. Elasticsearch ile çalışırken sıkça kullanacaksın.

cURL Temel Söz Dizimi

curl -X <METHOD> "http://localhost:9200/<path>" \
  -H 'Content-Type: application/json' \
  -d '<JSON_BODY>'

İlk cURL Komutları

# 1. Elasticsearch bilgisi
curl http://localhost:9200?pretty

# pretty parametresi JSON'u güzel formatlar
# Yanıt:
{
  "name" : "node-1",
  "cluster_name" : "docker-cluster",
  "version" : {
    "number" : "8.17.0"
  },
  "tagline" : "You Know, for Search"
}

# 2. Cluster sağlığı
curl http://localhost:9200/_cluster/health?pretty

# 3. Tüm index'leri listele
curl http://localhost:9200/_cat/indices?v

# 4. Node bilgileri
curl http://localhost:9200/_cat/nodes?v

cURL ile CRUD İşlemleri

# OLUŞTUR — Döküman ekle (POST, otomatik ID)
curl -X POST "localhost:9200/my-first-index/_doc?pretty" \
  -H 'Content-Type: application/json' \
  -d '{
    "title": "Elasticsearch Öğreniyorum",
    "author": "Ben",
    "date": "2025-01-15",
    "likes": 0
  }'

# Yanıt:
{
  "_index" : "my-first-index",
  "_id" : "abc123xyz",        ← Otomatik oluşturulan ID
  "_version" : 1,
  "result" : "created",       ← Başarıyla oluşturuldu
  "_primary_term" : 1,
  "_seq_no" : 0
}

# OLUŞTUR — Belirli ID ile (PUT)
curl -X PUT "localhost:9200/my-first-index/_doc/1?pretty" \
  -H 'Content-Type: application/json' \
  -d '{
    "title": "Docker ile Elasticsearch",
    "author": "Ben",
    "date": "2025-01-16",
    "likes": 5
  }'

# OKU — Dökümanı getir
curl "localhost:9200/my-first-index/_doc/1?pretty"

# ARA — Tüm dökümanları getir
curl "localhost:9200/my-first-index/_search?pretty"

# ARA — Belirli bir sorgu ile
curl -X GET "localhost:9200/my-first-index/_search?pretty" \
  -H 'Content-Type: application/json' \
  -d '{
    "query": {
      "match": {
        "title": "elasticsearch"
      }
    }
  }'

# SİL — Döküman sil
curl -X DELETE "localhost:9200/my-first-index/_doc/1?pretty"

# SİL — Tüm index'i sil
curl -X DELETE "localhost:9200/my-first-index?pretty"

cURL İpuçları

# -s (silent) — progress bar'ı gizle
curl -s localhost:9200/_cluster/health | jq .

# jq ile JSON formatlama (jq kurulu olmalı)
curl -s localhost:9200/_cat/indices?format=json | jq .

# -w ile response time ölçme
curl -s -o /dev/null -w "%{time_total}s\n" localhost:9200/products/_search

# -v (verbose) — HTTP header'larını gör
curl -v localhost:9200/_cluster/health

# Dosyadan sorgu okuma
curl -X GET "localhost:9200/products/_search?pretty" \
  -H 'Content-Type: application/json' \
  -d @query.json

Kibana Dev Tools — Ana Aracımız

Kibana Dev Tools, Elasticsearch REST API'sine sorgu göndermenin en pratik yoludur. cURL'den çok daha hızlı ve konforlu.

Dev Tools'a Erişim

  1. Tarayıcıda http://localhost:5601

  2. Sol menüden ManagementDev Tools seç

  3. Veya doğrudan: http://localhost:5601/app/dev_tools#/console

Dev Tools Söz Dizimi

cURL'den farklı olarak, Dev Tools'ta sadece HTTP metodu ve path yazarsın:

// cURL'de:
// curl -X GET "localhost:9200/products/_search" -H 'Content-Type: application/json' -d'{"query":{"match_all":{}}}'

// Dev Tools'ta:
GET /products/_search
{
  "query": {
    "match_all": {}
  }
}

Farklara dikkat et:

  • curl -X GET "localhost:9200 kısmı yok — Dev Tools bunu otomatik ekler

  • -H 'Content-Type: application/json' yok — otomatik

  • Body ayrı bir -d parametresi değil, doğrudan alt satırda

Dev Tools Kısayolları

Kısayolİşlev
Ctrl + EnterSorguyu çalıştır
Ctrl + /Yorum satırı ekle/kaldır
Ctrl + SpaceOtomatik tamamlama
Ctrl + IJSON'u formatla (auto-indent)
Ctrl + Up/DownSorgular arasında gezin

Dev Tools ile İlk Sorgular

Dev Tools'u aç ve sırasıyla bunları çalıştır:

// 1. Merhaba Elasticsearch!
GET /

// 2. Cluster sağlığı
GET /_cluster/health

// 3. Index oluştur
PUT /blog
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

// 4. Döküman ekle
POST /blog/_doc
{
  "title": "Elasticsearch'e İlk Adım",
  "content": "Bugün Elasticsearch öğrenmeye başladım. REST API ile konuşuyoruz!",
  "author": "Ahmet",
  "tags": ["elasticsearch", "başlangıç"],
  "created_at": "2025-01-15T10:00:00Z",
  "views": 0
}

// 5. Belirli ID ile döküman ekle
PUT /blog/_doc/1
{
  "title": "Docker ile Development",
  "content": "Docker Compose ile Elasticsearch ve Kibana'yı ayağa kaldırdık.",
  "author": "Mehmet",
  "tags": ["docker", "devops"],
  "created_at": "2025-01-16T14:30:00Z",
  "views": 42
}

// 6. Birkaç döküman daha ekle
PUT /blog/_doc/2
{
  "title": "REST API Nedir?",
  "content": "REST API, HTTP protokolü üzerinden kaynaklara erişim sağlayan bir mimari stildir.",
  "author": "Ahmet",
  "tags": ["api", "rest", "http"],
  "created_at": "2025-01-17T09:15:00Z",
  "views": 128
}

PUT /blog/_doc/3
{
  "title": "Kibana Dashboard Oluşturma",
  "content": "Kibana ile görsel dashboard'lar oluşturarak verini anlamlandırabilirsin.",
  "author": "Ayşe",
  "tags": ["kibana", "dashboard", "visualization"],
  "created_at": "2025-01-18T16:45:00Z",
  "views": 85
}

Arama Sorguları

// Tüm dökümanları getir
GET /blog/_search
{
  "query": {
    "match_all": {}
  }
}

// "elasticsearch" kelimesini ara
GET /blog/_search
{
  "query": {
    "match": {
      "content": "elasticsearch"
    }
  }
}

// Belirli bir yazarın yazılarını bul
GET /blog/_search
{
  "query": {
    "match": {
      "author": "Ahmet"
    }
  }
}

// Birden fazla alanda ara
GET /blog/_search
{
  "query": {
    "multi_match": {
      "query": "docker",
      "fields": ["title", "content", "tags"]
    }
  }
}

// Views'u 50'den büyük olanlar
GET /blog/_search
{
  "query": {
    "range": {
      "views": {
        "gt": 50
      }
    }
  }
}

API Yanıtlarını Okuma

Elasticsearch yanıtlarını anlamak çok önemli. Her alanın ne anlama geldiğini öğrenelim.

Döküman Ekleme Yanıtı

// POST /blog/_doc yanıtı:
{
  "_index": "blog",           // Hangi index'e eklendi
  "_id": "xYz123AbC",        // Dökümanın benzersiz ID'si
  "_version": 1,              // Versiyon numarası (her güncellemede artar)
  "result": "created",        // İşlem sonucu: created, updated, deleted
  "_shards": {
    "total": 1,               // Toplam shard sayısı
    "successful": 1,          // Başarılı yazılan shard
    "failed": 0               // Başarısız shard
  },
  "_seq_no": 0,               // Sıra numarası (optimistic concurrency için)
  "_primary_term": 1          // Primary term (lider shard değişimi takibi)
}

Arama Yanıtı

// GET /blog/_search yanıtı:
{
  "took": 5,                  // Sorgu süresi (milisaniye)
  "timed_out": false,         // Zaman aşımı oldu mu?
  "_shards": {
    "total": 1,               // Toplam taranan shard
    "successful": 1,          // Başarılı shard
    "skipped": 0,             // Atlanan shard
    "failed": 0               // Başarısız shard
  },
  "hits": {
    "total": {
      "value": 3,             // Toplam eşleşen döküman sayısı
      "relation": "eq"        // eq = tam sayı, gte = en az bu kadar
    },
    "max_score": 1.2345,      // En yüksek relevance skoru
    "hits": [                 // Döküman listesi (varsayılan 10 adet)
      {
        "_index": "blog",
        "_id": "1",
        "_score": 1.2345,     // Bu dökümanın skoru
        "_source": {           // Dökümanın kendisi
          "title": "Docker ile Development",
          "content": "Docker Compose ile...",
          "author": "Mehmet",
          "tags": ["docker", "devops"],
          "created_at": "2025-01-16T14:30:00Z",
          "views": 42
        }
      },
      // ... diğer dökümanlar
    ]
  }
}

Kritik alanlar:

  • took: Performans ölçümü — 5ms çok iyi, 500ms+ sorunlu olabilir

  • hits.total.value: Toplam eşleşme — pagination için önemli

  • _score: Relevance skoru — yüksek olan daha alakalı

  • _source: Dökümanın asıl içeriği


_cat API — İnsan Okunabilir Bilgi

_cat API'si, tablo formatında bilgi döner. JSON yerine düz metin — terminalde okumak kolay.

// Tüm index'leri listele
GET /_cat/indices?v

// Yanıt:
// health status index   uuid                   pri rep docs.count store.size
// yellow open   blog    xYz123...              1   1          4      12.3kb

// Node'ları listele
GET /_cat/nodes?v

// Shard dağılımını gör
GET /_cat/shards?v

// Cluster sağlığı (tek satır)
GET /_cat/health?v

// Belirli index'in shard'larını gör
GET /_cat/shards/blog?v

// Disk kullanımı
GET /_cat/allocation?v

// Thread pool durumu
GET /_cat/thread_pool?v&h=node_name,name,active,queue,rejected

// Bekleyen görevler
GET /_cat/pending_tasks?v

?v parametresi header (sütun başlıkları) ekler. Onsuz sadece veri gelir.

Sık kullanılan `_cat` endpoint'leri:

EndpointAçıklama
_cat/healthCluster durumu (green/yellow/red)
_cat/nodesNode listesi ve kaynak kullanımı
_cat/indicesIndex listesi, boyut, döküman sayısı
_cat/shardsShard dağılımı ve durumu
_cat/allocationDisk kullanımı per node
_cat/countToplam döküman sayısı
_cat/pluginsYüklü plugin'ler

Sık Kullanılan API Endpoint'leri

Cluster API'leri

// Cluster sağlığı (detaylı)
GET /_cluster/health

// Cluster ayarları
GET /_cluster/settings?include_defaults=true

// Cluster istatistikleri
GET /_cluster/stats

// Bekleyen cluster görevleri
GET /_cluster/pending_tasks

Index API'leri

// Index oluştur
PUT /products
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

// Index bilgisi
GET /products

// Index ayarları
GET /products/_settings

// Index mapping'i
GET /products/_mapping

// Index istatistikleri
GET /products/_stats

// Index'i kapat (aranmaz hale gelir, kaynak tasarrufu)
POST /products/_close

// Index'i aç
POST /products/_open

// Index'i sil
DELETE /products

// Index var mı kontrol et
HEAD /products
// 200 → var, 404 → yok

Döküman API'leri

// Döküman ekle (otomatik ID)
POST /products/_doc
{
  "name": "Laptop",
  "price": 15000
}

// Döküman ekle/güncelle (belirli ID)
PUT /products/_doc/1
{
  "name": "Laptop",
  "price": 15000
}

// Döküman oku
GET /products/_doc/1

// Sadece _source (metadata olmadan)
GET /products/_source/1

// Döküman var mı kontrol et
HEAD /products/_doc/1
// 200 → var, 404 → yok

// Döküman sil
DELETE /products/_doc/1

// Kısmi güncelleme
POST /products/_update/1
{
  "doc": {
    "price": 14500
  }
}

Pratik Senaryo: Mini E-Ticaret

Öğrendiklerimizi bir araya getirelim. Bir e-ticaret senaryosu kuracağız:

Adım 1: Index Oluştur

PUT /products
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

Adım 2: Ürün Ekle

// Toplu ürün ekleme (Bulk API — detayları Bölüm 3'te)
POST /_bulk
{"index": {"_index": "products", "_id": "1"}}
{"name": "MacBook Pro 16", "category": "Laptop", "price": 75000, "brand": "Apple", "in_stock": true, "description": "M3 Pro çipli profesyonel laptop", "rating": 4.8}
{"index": {"_index": "products", "_id": "2"}}
{"name": "ThinkPad X1 Carbon", "category": "Laptop", "price": 45000, "brand": "Lenovo", "in_stock": true, "description": "İş dünyası için ultra hafif laptop", "rating": 4.5}
{"index": {"_index": "products", "_id": "3"}}
{"name": "iPhone 15 Pro", "category": "Telefon", "price": 62000, "brand": "Apple", "in_stock": false, "description": "Titanium kasa, A17 Pro çip", "rating": 4.7}
{"index": {"_index": "products", "_id": "4"}}
{"name": "Samsung Galaxy S24 Ultra", "category": "Telefon", "price": 55000, "brand": "Samsung", "in_stock": true, "description": "AI destekli Galaxy deneyimi", "rating": 4.6}
{"index": {"_index": "products", "_id": "5"}}
{"name": "Sony WH-1000XM5", "category": "Kulaklık", "price": 9500, "brand": "Sony", "in_stock": true, "description": "Gürültü engelleyici kablosuz kulaklık", "rating": 4.7}
{"index": {"_index": "products", "_id": "6"}}
{"name": "AirPods Pro 2", "category": "Kulaklık", "price": 8500, "brand": "Apple", "in_stock": true, "description": "USB-C, aktif gürültü engelleme", "rating": 4.6}
{"index": {"_index": "products", "_id": "7"}}
{"name": "Dell UltraSharp 27 4K", "category": "Monitör", "price": 12000, "brand": "Dell", "in_stock": true, "description": "27 inç 4K IPS profesyonel monitör", "rating": 4.4}
{"index": {"_index": "products", "_id": "8"}}
{"name": "Logitech MX Master 3S", "category": "Mouse", "price": 2800, "brand": "Logitech", "in_stock": true, "description": "Ergonomik kablosuz mouse, sessiz tıklama", "rating": 4.8}

Adım 3: Aramalara Başla

// Tüm ürünleri listele
GET /products/_search
{
  "query": { "match_all": {} }
}

// "laptop" ara
GET /products/_search
{
  "query": {
    "match": {
      "name": "laptop"
    }
  }
}

// Apple ürünlerini bul
GET /products/_search
{
  "query": {
    "match": {
      "brand": "Apple"
    }
  }
}

// Fiyatı 10000-50000 arası ürünler
GET /products/_search
{
  "query": {
    "range": {
      "price": {
        "gte": 10000,
        "lte": 50000
      }
    }
  }
}

// Stokta olan Apple ürünleri, fiyata göre sıralı
GET /products/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": { "brand": "Apple" } }
      ],
      "filter": [
        { "term": { "in_stock": true } }
      ]
    }
  },
  "sort": [
    { "price": "asc" }
  ]
}

// "gürültü engelleme" ara (description'da)
GET /products/_search
{
  "query": {
    "match": {
      "description": "gürültü engelleme"
    }
  }
}

// Kategori bazında ürün sayısı (aggregation)
GET /products/_search
{
  "size": 0,
  "aggs": {
    "categories": {
      "terms": {
        "field": "category.keyword"
      }
    }
  }
}

// Ortalama fiyat
GET /products/_search
{
  "size": 0,
  "aggs": {
    "avg_price": {
      "avg": {
        "field": "price"
      }
    }
  }
}

Adım 4: Güncelleme ve Silme

// Fiyat güncelle
POST /products/_update/1
{
  "doc": {
    "price": 72000
  }
}

// Döküman sil
DELETE /products/_doc/8

// Güncel durumu kontrol et
GET /products/_doc/1
GET /products/_count

Query String Arama (Hızlı Arama)

URL query string ile de arama yapabilirsin — basit aramalar için pratik:

// q parametresi ile arama
GET /products/_search?q=laptop

// Belirli alanda arama
GET /products/_search?q=name:laptop

// Birden fazla terim
GET /products/_search?q=name:laptop AND brand:Apple

// Varsayılan operatörü değiştir
GET /products/_search?q=laptop+apple&default_operator=AND

// Sonuç sayısını sınırla
GET /products/_search?q=laptop&size=3

// Belirli alanları getir
GET /products/_search?q=laptop&_source=name,price,brand

⚠️ Dikkat: Query string arama basit sorguları hızlıca yazmak için güzel ama karmaşık sorgularda Query DSL kullan. Query string'de escape, encoding sorunları çıkabilir.


Yararlı Parametreler

?pretty — Güzel Formatlama

# Formatlanmamış (tek satır)
curl localhost:9200/products/_search

# Formatlanmış (okunabilir)
curl localhost:9200/products/_search?pretty

?format=yaml — YAML Formatı

GET /_cluster/health?format=yaml

?human — İnsan Okunabilir Değerler

GET /_cat/indices?v&h=index,docs.count,store.size&bytes=b
// store.size: 12345 (byte)

GET /_cat/indices?v&h=index,docs.count,store.size
// store.size: 12.3kb (insan okunabilir)

_source Filtreleme

// Sadece belirli alanları getir
GET /products/_search
{
  "_source": ["name", "price"],
  "query": { "match_all": {} }
}

// Bazı alanları hariç tut
GET /products/_search
{
  "_source": {
    "excludes": ["description"]
  },
  "query": { "match_all": {} }
}

size ve from — Sayfalama

// İlk 3 sonuç
GET /products/_search
{
  "size": 3,
  "query": { "match_all": {} }
}

// 4. sonuçtan itibaren 3 sonuç (sayfa 2)
GET /products/_search
{
  "from": 3,
  "size": 3,
  "query": { "match_all": {} }
}

Java ile İlk API Çağrıları

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.core.*;
import co.elastic.clients.elasticsearch.core.search.Hit;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;

import java.util.Map;

class Main {
    public static void main(String[] args) throws Exception {
        // Client oluştur
        RestClient restClient = RestClient.builder(
            new HttpHost("localhost", 9200)
        ).build();
        ElasticsearchClient client = new ElasticsearchClient(
            new RestClientTransport(restClient, new JacksonJsonpMapper())
        );

        // 1. Cluster bilgisi
        var info = client.info();
        System.out.println("Cluster: " + info.clusterName());
        System.out.println("Version: " + info.version().number());

        // 2. Döküman ekle
        Map<String, Object> product = Map.of(
            "name", "Mechanical Keyboard",
            "price", 3500,
            "brand", "Keychron",
            "in_stock", true
        );

        IndexResponse indexResponse = client.index(i -> i
            .index("products")
            .id("100")
            .document(product)
        );
        System.out.println("Eklendi: " + indexResponse.result());

        // 3. Döküman oku
        GetResponse<Map> getResponse = client.get(g -> g
            .index("products")
            .id("100"),
            Map.class
        );
        if (getResponse.found()) {
            System.out.println("Bulundu: " + getResponse.source());
        }

        // 4. Arama yap
        SearchResponse<Map> searchResponse = client.search(s -> s
            .index("products")
            .query(q -> q
                .match(m -> m
                    .field("name")
                    .query("keyboard")
                )
            ),
            Map.class
        );

        System.out.println("Sonuç sayısı: " + searchResponse.hits().total().value());
        for (Hit<Map> hit : searchResponse.hits().hits()) {
            System.out.println(hit.score() + " → " + hit.source());
        }

        // 5. Döküman sil
        DeleteResponse deleteResponse = client.delete(d -> d
            .index("products")
            .id("100")
        );
        System.out.println("Silindi: " + deleteResponse.result());

        restClient.close();
    }
}

Best Practices

Kibana Dev Tools'u ana aracın yap — Autocomplete, syntax highlighting, history

?pretty kullan — cURL'de JSON çıktıyı okunabilir yap

_cat API'yi öğren — Hızlı durum kontrolü için _cat/health, _cat/indices, _cat/nodes

Yanıtları okutook, _score, _shards, result alanlarını anla

Bulk API kullan — Birden fazla döküman eklerken tek tek değil toplu ekle

_source filtreleme yap — İhtiyacın olmayan alanları getirme, ağ trafiğini azalt


Yaygın Hatalar

❌ Content-Type header'ı unutma

# YANLIŞ — 406 Not Acceptable hatası
curl -X POST "localhost:9200/test/_doc" -d '{"name":"test"}'

# DOĞRU
curl -X POST "localhost:9200/test/_doc" -H 'Content-Type: application/json' -d '{"name":"test"}'

Elasticsearch 8.x'te Content-Type header'ı zorunludur. Kibana Dev Tools'ta bunu düşünmene gerek yok — otomatik eklenir.

❌ Geçersiz JSON gönderme

// YANLIŞ — trailing comma
POST /test/_doc
{
  "name": "test",
  "price": 100,     ← Bu virgül hata verir
}

// DOĞRU
POST /test/_doc
{
  "name": "test",
  "price": 100
}

❌ Index adında büyük harf kullanma

// YANLIŞ
PUT /MyProducts

// DOĞRU
PUT /my-products
PUT /my_products

Elasticsearch index adları küçük harf olmak zorundadır. Tire (-) ve alt çizgi (_) kullanabilirsin.

❌ Bulk API formatını yanlış yazma

// YANLIŞ — her satır ayrı JSON olmalı, güzel formatlanmış JSON olmaz
POST /_bulk
{
  "index": {
    "_index": "test",
    "_id": "1"
  }
}
{
  "name": "test"
}

// DOĞRU — her JSON tek satırda, NDJSON formatı
POST /_bulk
{"index":{"_index":"test","_id":"1"}}
{"name":"test"}

Bulk API NDJSON (Newline Delimited JSON) formatı kullanır. Her satır ayrı bir JSON objesi olmalı.

❌ _search sonuçlarında sadece ilk 10'a bakmak

Varsayılan size 10'dur. Daha fazla sonuç istiyorsan size parametresini belirt. Ama dikkat: size 10.000'den büyük olamaz (varsayılan). Büyük veri setlerinde search_after veya scroll kullan.


Özet

  • Elasticsearch ile tüm iletişim HTTP REST API üzerinden JSON formatında yapılır

  • cURL komut satırından, Kibana Dev Tools tarayıcıdan sorgu göndermenin yoludur

  • Her API yanıtında took, _score, _shards, result gibi bilgi alanları bulunur

  • _cat API (_cat/indices, _cat/health, _cat/nodes) hızlı durum kontrolü için idealdir

  • Index adları küçük harf olmalı, Bulk API NDJSON formatı kullanır

  • Kibana Dev Tools, autocomplete ve syntax highlighting ile cURL'den çok daha pratiktir

Bir sonraki bölümde Elasticsearch'ün temel kavramlarına dalacağız — Index, Document, Field, Mapping, Shards ve Inverted Index yapısını öğreneceğiz!