Tuesday 11 July 2017

[Dev Note] Elasticsearch

         Elasticsearch是一個基於Apache Lucene(TM)的開源搜索引擎。無論在開源還是專有領域,Lucene可以被認為是迄今為止最先進、性能最好的、功能最全的搜索引擎庫。

       但是,Lucene只是一個庫。想要使用它,你必須使用Java來作為開發語言並將其直接集成到你的應用中,更糟糕的是,Lucene非常復雜,你需要深入了解檢索的相關知識來理解它是如何工作的。

       Elasticsearch也使用Java開發並使用Lucene作為其核心來實現所有索引和搜索的功能,但是它的目的是通過簡單的RESTful API來隱藏Lucene的復雜性,從而讓全文搜索變得簡單。

       不過,Elasticsearch不僅僅是Lucene和全文搜索,我們還能這樣去描述它:

  •  分布式的實時文件存儲,每個字段都被索引並可被搜索
  • 分布式的實時分析搜索引擎
  • 可以擴展到上百臺服務器,處理PB級結構化或非結構化數據

      而且,所有的這些功能被集成到一個服務裏面,你的應用可以通過簡單的RESTful API、各種語言的客戶端甚至命令行與之交互。
上手Elasticsearch非常容易。它提供了許多合理的缺省值,並對初學者隱藏了復雜的搜索引擎理論。它開箱即用(安裝即可使用),只需很少的學習既可在生產環境中使用。

實際應用 :
      1. 快取資料庫    : 可以作為第一次搜尋,一旦沒有再去資料庫查詢
      2. Index 資料庫  : 用來查詢Index,Index 用來在資料庫查詢,可以節省時間提高效率
      3. Log 資料庫     : 查詢系統LOG

可以參考面兩個案例





Online Book : https://es.xiaoleilu.com/010_Intro/05_What_is_it.html

Plugin  - head : https://mobz.github.io/elasticsearch-head/

Installation :

https://www.elastic.co/guide/en/elasticsearch/reference/current/windows.html

DownLoad : 


https://www.elastic.co/downloads/elasticsearch


Step:

1.I download zip and then unzip it into a folder.

2. execute  elasticsearch.bat under bin folder.


3. Open Browser and connect to "http://localhost:9200/"


4. Insert data

Method : POST
URL : http://localhost:9200/places/restaurant


{
 "name":"Kenneth",
 "description":"Best pasta around",
 "address" :{
  "street":"464 S main St",
  "city":"Singapore",
  "state":"SG",
  "zip":"90013"
  
 },
 "location": [34.0239,-118.3927],
 "tags":["pasta", "spaghetti"],
 "rating" :45
 
}



5.Search data

Method : GET
URL : http://localhost:9200/places/restaurant/_search




6. Bulk
   Method : GET
URL : http://localhost:9200/_bulk
Data : https://gist.github.com/clintongormley/8579281





核心簡單字段類型


Elasticsearch支持以下簡單字段類型:



類型表示的數據類型
Stringstring
Whole numberbyteshortintegerlong
Floating pointfloatdouble
Booleanboolean
Datedate

當你索引一個包含新字段的文檔——一個之前沒有的字段——Elasticsearch將使用動態映射猜測字段類型,這類型來自於JSON的基本數據類型,使用以下規則:


JSON typeField type
Boolean: true or false"boolean"
Whole number: 123"long"
Floating point: 123.45"double"
String, valid date: "2014-09-15""date"
String: "foo bar""string"


No comments:

Post a Comment

how-to-recursively-create-subfolder-in-each-folder-of-a-directory-in-cmd

test.cmd: @echo off setlocal for /f "usebackq tokens=*" %%a in (`dir /b /a:d`) do ( rem enter the directory pushd %%a echo...