安裝Elasticsearch
Elasticsearch須要JDK的支持,因此首先須要安裝JDK,本文裏咱們用的JDK是1.7版本的,關於JDK的安裝這裏不作額外說明。python
jdk的安裝完成後能夠從 https://www.elastic.co/downloads/elasticsearch 下載最新的elasticsearch安裝包elasticsearch-2.3.2.zip。api
將elasticsearch-2.3.2.zip 上傳到VM環境的機器192.168.248.128的目錄/home 下,用命令行切換到home目錄下並修改文件權限爲hadoop最後解壓文件curl
chown hadoop:hadoop elasticsearch-2.3.2 unzip elasticsearch-2.3.2
解壓文件後將解壓文件目錄下的config目錄權限修改成hadoopelasticsearch
chown hadoop:hadoop config
最終結果如圖
oop
最後切換到hadoop用戶並再/home/elasticsearch-2.3.2目錄下啓動elasticsearch測試
su hadoop ./bin/elasticsearch
成功啓動後能夠在另外一個終端測試url
curl 'http://localhost:9200/?pretty'
結果以下spa
當elasticsearch在前臺運行時能夠經過ctrl+c來中止,或者經過以下api來終止運行
命令行
curl -XPOST 'http://localhost:9200/shutdown'
基本API操做
curl -XPUT 'http://localhost:9200/megacorp/employee/1' -d '{"first_name":"John","last_name":"Smith","age":"25","about":"I love to go rock climbing","interests":["sports","music"]}' #查詢 curl -XGET 'http://localhost:9200/megacorp/employee/1?pretty'
查詢結果以下rest
查詢about字段包含basketball字段 的結果
curl -XGET 'http://localhost:9200/megacorp/employee/_search?pretty' -d '{"query":{"match":{"about":"basketball"}}}'
結果以下
查詢記錄中各個interests的數量(即按照interests分組統計)
-XGET 'http://localhost:9200/megacorp/employee/_search?pretty' -d '{"aggs":{"all_interests":{"terms":{"field":"interests"}}}}'
部分結果以下