ELASTICSEARCH Mark Elasticsearch Elasticsearch Lucene REST api 1

  • Slides: 48
Download presentation
ELASTICSEARCH 戴君翰 ( Mark )

ELASTICSEARCH 戴君翰 ( Mark )

Elasticsearch 簡介 Elasticsearch = Lucene + REST api 建立索引以達到快速�詢資料 1 , Mark , 25

Elasticsearch 簡介 Elasticsearch = Lucene + REST api 建立索引以達到快速�詢資料 1 , Mark , 25 , Taipei 2 , Eric , 30 , Taipei 3 , Lucas , 25 , Taipei DB Index ID Name Age City Name ID Age ID 1 Mark 25 Taipei Mark 1 25 1, 3 2 Eric 30 Taipei Eric 2 30 2 3 Lucas 25 Taipei Lucas 3 City ID Taipei 1, 2, 3

Elasticsearch 簡介 叢集架構易於擴張與備份 � Replica Set � Shard

Elasticsearch 簡介 叢集架構易於擴張與備份 � Replica Set � Shard

Elasticsearch 簡介 REST api 方便資料管理 � URI分為 3個區塊 Localhost: 9200 / index / type

Elasticsearch 簡介 REST api 方便資料管理 � URI分為 3個區塊 Localhost: 9200 / index / type / id � 分別對應傳統資料庫的 DB / table / primary key 傳統SQL資料庫 Elasticsearch DB Index Table Type Primary key Id Row Document Column ( Schema ) Field

Elasticsearch 安裝 下載 Elasticsearch 程式 � https: //www. elastic. co/ � 執行elasticsearch. exe �

Elasticsearch 安裝 下載 Elasticsearch 程式 � https: //www. elastic. co/ � 執行elasticsearch. exe � http: //localhost: 9200 � You Know, for Search

Elasticsearch 安裝 安裝圖形化介面套件 � Head � http: //mobz. github. io/elasticsearch-head/ � plugin -install mobz/elasticsearch-head

Elasticsearch 安裝 安裝圖形化介面套件 � Head � http: //mobz. github. io/elasticsearch-head/ � plugin -install mobz/elasticsearch-head

因為是REST 所以你其實也可以用CURL � http: //curl. haxx. se/download. html � 快速下載網址 � http: //curl. haxx.

因為是REST 所以你其實也可以用CURL � http: //curl. haxx. se/download. html � 快速下載網址 � http: //curl. haxx. se/dlwiz/? type=bin&os=Win 64&fla v=-&ver=curl -XPOST localhost: 9200/index_test/type/1 -d ' { "test": 1234 }'

另外一種資料流 在Elasticsearch世界中有種接資料的形式 � 資料流,一直流,所以稱之為河? � Twitter River https: //github. com/elasticsearch-river-twitter

另外一種資料流 在Elasticsearch世界中有種接資料的形式 � 資料流,一直流,所以稱之為河? � Twitter River https: //github. com/elasticsearch-river-twitter

Twitter River 使用 安裝 River 套件 � plugin install elasticsearch/elasticsearch-river-twitter/2. 4. 2 設定 River

Twitter River 使用 安裝 River 套件 � plugin install elasticsearch/elasticsearch-river-twitter/2. 4. 2 設定 River 套件 � POST _river/my_twitter_river/_meta

Twitter Token 取得 申請Twitter帳號 � 手機認證(不會過) � 改用手機登入Twitter也可以通過手機認證 Create APP � https: //twitter. com/

Twitter Token 取得 申請Twitter帳號 � 手機認證(不會過) � 改用手機登入Twitter也可以通過手機認證 Create APP � https: //twitter. com/ https: //apps. twitter. com/ 產生Token

Elasticsearch 查詢語法 Elastic Search常用的Query語法 Boolean query � 有三個區塊 � Must ( 絕對要成立 ) Must_not

Elasticsearch 查詢語法 Elastic Search常用的Query語法 Boolean query � 有三個區塊 � Must ( 絕對要成立 ) Must_not ( 絕不可以成立 ) Should ( 可有可無 ) { "query": { "bool": { "must": [], "must_not": [], "should": [] } } }

關鍵字有了,限制時間呢? 給個範例! { "range": { "opinion. created_time": { "from": "2014 -09 -28", "to": "2014

關鍵字有了,限制時間呢? 給個範例! { "range": { "opinion. created_time": { "from": "2014 -09 -28", "to": "2014 -09 -29" } } } { "range": { "opinion. created_time": { "from": "2014 -09 -25", "to": “now" } } } 5 2 9 -2 0 014 201 6 4 -2 -09 4 201 27 9 -0 4 201 28 9 -0 4 201 29 9 -0 201 4 30 9 -0

對時間做group by? 對時間做Aggregation � � � Date_histogram 欄位必須是時間型態 Interval表示間格時間 year , month, week, day

對時間做group by? 對時間做Aggregation � � � Date_histogram 欄位必須是時間型態 Interval表示間格時間 year , month, week, day Hour, minute, second 當然也可以簡寫 也可以配上數值 { } "aggs" : { "articles_over_time" : "date_histogram" : "field" : "date" "interval" : "1. } } }

佈局介紹 Query Filter Row 1 Row 2 Row 3

佈局介紹 Query Filter Row 1 Row 2 Row 3

Query介紹 Query 語法 � query. String � 全文檢索( 所有field ) A ( 空格 )

Query介紹 Query 語法 � query. String � 全文檢索( 所有field ) A ( 空格 ) B => A or B A OR B A AND B (A OR B) AND (C OR D) � 指定欄位 Text : A => text field包含A

Elasticsearch 基本效能調教 效能調教基本招 � 調大Memory � 設定環境變數 ES_MIN_MEM & ES_MAX_MEM 基本上越大越好,建議不要超過系統記憶體的一半 修改設定檔(config/elasticsearch. yml) bootstrap.

Elasticsearch 基本效能調教 效能調教基本招 � 調大Memory � 設定環境變數 ES_MIN_MEM & ES_MAX_MEM 基本上越大越好,建議不要超過系統記憶體的一半 修改設定檔(config/elasticsearch. yml) bootstrap. mlockall: true => 鎖住記憶體不做swap 設定threadpool threadpool. search. type: fixed threadpool. search. size: 20 threadpool. search. queue_size: 100 threadpool. bulk. type: fixed threadpool. bulk. size: 60 threadpool. bulk. queue_size: 300