Aklımda Kalası Kelimeler

* давайте работать вместе
* Zarf ve Mazruf, Zerafet(xHoyratlık) ile aynı kökten(za-ra-fe) gelir
* Bedesten
* Suç subuta ermiştir - Suç sabit olmuştur
elasticsearch etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
elasticsearch etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

11 Kasım 2015 Çarşamba

Marvel pluginini nasıl yükleriz?

ES klasörüne gidelim
C:\>cd C:\Program Files\Elasticsearch\bin
C:\Program Files\Elasticsearch\bin>Plugin.bat -i elasticsearch/marvel/latest
Eğer yüklemede sorun yaşarsanız bilinki bu klasöre yazma hakkınız olmayabilir Failed to install elasticsearch/marvel/latest, reason: plugin directory C:\Program Files\Elasticsearch\plugins is read only” then create a ‘plugins’ directory to root of your ElasticSearch installation path and make it write and Read write permissions for all user. ElasticSearch servisini yeniden başlatalım. Şimdi browserda görelim: http://localhost:9200/_plugin/marvel ‘Dashboard’ menüsünden ‘sense’ seçeneğini seçerek kod yazabilirsiniz.

13 Mart 2015 Cuma

Elasticsearch ile uygulama loglama - Application logging with Elasticsearch

Önce elasticsearch head plugin windows'a nasıl kurulur:

Plugin bize durumu görme sorgu gönderme vs. kolaylıkları sağlayacak:

  1. Önce log indexini yaratalım
  2. Sonra loglanacak hash'imizin veri yapısına göre mapping
  3. verimizi girelim
  4. Tüm verilerimizi görecek sorgu çakalım

  1. Önce log indexi olan diviner_log'u oluşturalım:
    PUT http://localhost:9200/diviner_log/
  2. Hash'imize göre map oluşturalım. Buradaki püf noktası automatic _id yaratıyor olmamız ve bu id için gönderdiğimiz içinde milisaniyelik bilgi olan tarih alanını kullanacağız. Bu sayede loglamak istediğimiz bilginin id alanından loglarına erişeceğiz ama tarih alanı her defasında farklı gideceği için versiyonlamış olacağız. Elasticsearch'ün aynı _id değerine PUT ile gönderdiğimiz değerlerin kaçıncı _versyion olduğunu söylemesine rağmen X versiyonunu çekip vermemesi nedeniyle eşsiz _id değerlerini işlemin gerçekleştiği tarih olarak oluşturuyoruz:
    PUT http://localhost:9200/diviner_log/ihale/_mapping
    {
      "ihale": {
        "_id": {
          "path": "tarihi"
        },
        "properties": {
          "id": {
            "type": "long"
          },
          "konusu": {
            "type": "string"
          },
          "tarihi": {
            "type": "date"
          }
        }
      }
    }
    Hadi birde _mapping sonucuna bakalım nasıl olmuş:
    Mapping sonucunu görelim:
    GET http://localhost:9200/diviner_log/ihale/_mapping
    {
      "diviner_log": {
        "mappings": {
          "ihale": {
            "_id": {
              "path": "tarihi"
            },
            "properties": {
              "id": {
                "type": "long"
              },
              "konusu": {
                "type": "string"
              },
              "tarihi": {
                "type": "date",
                "format": "dateOptionalTime"
              }
            }
          }
        }
      }
    }
  3. Veri girelim
    POST http://localhost:9200/diviner_log/ihale/
    {
      "id": 1,
      "konusu": "Diyaliz makinesi alımı",
      "tarihi": "2015-03-12T15:44:50.488Z"
    }

    Cevabı:
    {
      "_index": "diviner_log",
      "_type": "ihale",
      "_id": "2015-03-12T15:44:50.488Z",
      "_version": 1,
      "created": true
    }

  4. Tüm verilerimizi görecek sorgu çakalım
    {
      "query": {
        "bool": {
          "must": [
            {
              "wildcard": {
                "ihale.konusu": "*"
              }
            }
          ],
          "must_not": [],
          "should": []
        }
      },
      "from": 0,
      "size": 10,
      "sort": [],
      "facets": {}
    }

    Sonuçlar:
    {
      "took": 8,
      "timed_out": false,
      "_shards": {
        "total": 6,
        "successful": 6,
        "failed": 0
      },
      "hits": {
        "total": 4,
        "max_score": 1,
        "hits": [
          {
            "_index": "diviner_log",
            "_type": "ihale",
            "_id": "2015-03-12T15:44:50.489Z",
            "_score": 1,
            "_source": {
              "id": 2,
              "konusu": "AV Seti alımı",
              "tarihi": "2015-03-12T15:44:50.489Z"
            }
          },
          {
            "_index": "diviner_log",
            "_type": "ihale",
            "_id": "2015-03-12T15:44:50.491Z",
            "_score": 1,
            "_source": {
              "id": 2,
              "konusu": "AV Seti alımı - ver 3",
              "tarihi": "2015-03-12T15:44:50.491Z"
            }
          },
          {
            "_index": "diviner_log",
            "_type": "ihale",
            "_id": "2015-03-12T15:44:50.488Z",
            "_score": 1,
            "_source": {
              "id": 1,
              "konusu": "Diyaliz makinesi alımı",
              "tarihi": "2015-03-12T15:44:50.488Z"
            }
          },
          {
            "_index": "diviner_log",
            "_type": "ihale",
            "_id": "2015-03-12T15:44:50.490Z",
            "_score": 1,
            "_source": {
              "id": 2,
              "konusu": "AV Seti alımı - ver 2",
              "tarihi": "2015-03-12T15:44:50.490Z"
            }
          }
        ]
      }
    }




  5. Şimdi id değerine göre loglara bakalım:



  6. Gelen sonuçlar score'a göre sıralandı ama bizim log sonuçları işlem tarihine göre sıralansın:
    {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "ihale.id": "2"
              }
            }
          ],
          "must_not": [],
          "should": []
        }
      },
      "from": 0,
      "size": 10,
      "sort": [
        {
          "ihale.tarihi": {
            "order": "asc"
          }
        }
      ],
      "facets": {}
    }

    Sonuç kümesini görelim:
    ... "hits": [
        {
          "_index": "diviner_log",
          "_type": "ihale",
          "_id": "2015-03-12T15:44:50.489Z",
          "_score": null,
          "_source": {
            "id": 2,
            "konusu": "AV Seti alımı",
            "tarihi": "2015-03-12T15:44:50.489Z"
          },
          "sort": [
            1426175090489
          ]
        },
        {
          "_index": "diviner_log",
          "_type": "ihale",
          "_id": "2015-03-12T15:44:50.490Z",
          "_score": null,
          "_source": {
            "id": 2,
            "konusu": "AV Seti alımı - ver 2",
            "tarihi": "2015-03-12T15:44:50.490Z"
          },
          "sort": [
            1426175090490
          ]
        },
        {
          "_index": "diviner_log",
          "_type": "ihale",
          "_id": "2015-03-12T15:44:50.491Z",
          "_score": null,
          "_source": {
            "id": 2,
            "konusu": "AV Seti alımı - ver 3",
            "tarihi": "2015-03-12T15:44:50.491Z"
          },
          "sort": [
            1426175090491
          ]
        }
      ]...




12 Mart 2015 Perşembe

Elasticsearch notarım

{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "ihale" : {
            "_source" : { "enabled" : false },
            "_type" : {"index" : "no"},
            "_id" : {
                "index" : "not_analyzed",
                "store" : true
            },
            "properties" : {
                "id" : { "type" : "long", "index" : "not_analyzed" },
                "konusu" : { "type" : "string", "index" : "not_analyzed" }
            }
        }
    }
}
--------------------------------------------------------------------------------------------------------
PUT http://localhost:9200/diviner_log/ HTTP/1.1
User-Agent: Fiddler
Host: localhost:9200
Content-Length: 404

{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "ihale" : {
            "_source" : { "enabled" : false },
            "_type" : {"index" : "no"},
            "properties" : {
                "id" : { "type" : "long", "index" : "not_analyzed" },
                "konusu" : { "type" : "string", "index" : "not_analyzed" }
            }
        }
    }
}

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 21

{"acknowledged":true}
--------------------------------------------------------------------------------------------------------  
:9200/index/_type/_id 
index için > GET http://localhost:9200/diviner_log/_mappings
_type için > GET http://localhost:9200/diviner_log/tweet/_mapping
--------------------------------------------------------------------------------------------------------   

MAPPINGS vs MAPPING

PUT http://localhost:9200/diviner_log/tweet/_mapping HTTP/1.1 // _mapping ile tek bir 
User-Agent: Fiddler
Host: localhost:9200
Content-Length: 402

{
            "_source" : { "enabled" : false },
            "_type" : {"index" : "no"},
            "_id" : { "path" : "tarihi" }, // :9200/index/_type/_id > _id değerini "tarihi" özelliğinden alacak
            "properties" : {
                "id" : { "type" : "long", "index" : "not_analyzed" },
                "konusu" : { "type" : "string", "index" : "not_analyzed" },
                "tarihi":{ "type" : "date", "index" : "not_analyzed" }  // "tarihi" özelliğinin tipinin date olduğunu belirtelim ki; 
                        // kibana'da süzme işlemleri kolay olsun
            }
}

İhale için mapping:
PUT http://localhost:9200/diviner_log/ihale/_mapping
{
  "ihale": {
    "_id": {
      "path": "tarihi"
    },
    "properties": {
      "id": {
        "type": "long"
      },
      "konusu": {
        "type": "string"
      },
      "tarihi": {
        "type": "date"
      }
    }
  }
}

Mapping sonucunu görelim:
GET http://localhost:9200/diviner_log/ihale/_mapping
{
  "diviner_log": {
    "mappings": {
      "ihale": {
        "_id": {
          "path": "tarihi"
        },
        "properties": {
          "id": {
            "type": "long"
          },
          "konusu": {
            "type": "string"
          },
          "tarihi": {
            "type": "date",
            "format": "dateOptionalTime"
          }
        }
      }
    }
  }
}

--------------------------------------------------------------------------------------------------------   
CLEAR CACHE - ELASTICSEARCH
$ curl -XPOST 'http://localhost:9200/twitter/_cache/clear'
--------------------------------------------------------------------------------------------------------   

AUTO CREATE ID 

POST http://localhost:9200/diviner_log/tweet/ HTTP/1.1 // PUT yerine POST ile gönderince otomatik ID üretecektir
User-Agent: Fiddler
Host: localhost:9200
Content-Length: 74

{id:1, konusu:"Cemin deneme tahtasındaki ilk konu", tarihi:1426086937374}


HTTP/1.1 201 Created
Content-Type: application/json; charset=UTF-8
Content-Length: 97

{"_index":"diviner_log","_type":"tweet","_id":"AUwM_9mGuoX-zfkMiNtf","_version":1,"created":true}

--------------------------------------------------------------------------------------------------------   

10 Mart 2015 Salı

ElasticSearch Windows 7'de çalışsın

Zip dosyasını indirelim:

Dosyayı klasöre açalım:

Java_Home ayarının yapılması:


Çalıştıralım:

Çalıştı:

Buna bir de kibana'yı bağladım:

Çalıştıralım Kibanayı

Arayüz nasılmış?

Buradan Elasticsearch nasıl kullanılırı daha iyi kavrayabilirsiniz: Joel Abrahamsson
Kitabı