elasticSearch學習筆記


僅需要jdk,下載解壓即可,最好修改下elasticsearch.yml

cluster.name
node.name

 

es有非常豐富的插件,建議安裝下面幾個

bigdesk

資源監控和集群管理插件
bin/plugin -install lukas-vlcek/bigdesk
http://127.0.0.1:9200/_plugin/bigdesk

 

elasticsearch-head

數據查詢插件
bin/plugin -install mobz/elasticsearch-head
http://localhost:9200/_plugin/head/

  

elasticsearch-kopf

集群資源查看和查詢插件,和head一起用吧,head偏數據查詢一點
bin/plugin --install lmenezes/elasticsearch-kopf
http://localhost:9200/_plugin/kopf

 

es是文檔數據庫,和一般rdbms的類比

關系數據庫     ⇒ 數據庫 ⇒ 表    ⇒ 行    ⇒ 列(Columns)
Elasticsearch  ⇒ 索引   ⇒ 類型  ⇒ 文檔  ⇒ 字段(Fields)

具體的可以通過head插件查看

 

建立3個測試數據

PUT /megacorp/employee/1
{
    "first_name" : "John",
    "last_name" :  "Smith",
    "age" :        25,
    "about" :      "I love to go rock climbing",
    "interests": [ "sports", "music" ]
}

PUT /megacorp/employee/2
{
    "first_name" :  "Jane",
    "last_name" :   "Smith",
    "age" :         32,
    "about" :       "I like to collect rock albums",
    "interests":  [ "music" ]
}

PUT /megacorp/employee/3
{
    "first_name" :  "Douglas",
    "last_name" :   "Fir",
    "age" :         35,
    "about":        "I like to build cabinets",
    "interests":  [ "forestry" ]
}

 

es的查詢非常強大,舉個讓cassandra蛋疼的模糊查詢的例子

POST /megacorp/employee/_search
{
  "fields": [
    "first_name"
  ],
  "query": {
    "wildcard": {
      "last_name": "*mi*"
    }
  }
}

fields是顯示哪些字段,具體的dsl看http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-query.html

 

再貼一個and查詢

POST /megacorp/employee/_search
{
"query": { "bool": { "must": [ { "wildcard": { "last_name": "*mi*" } }, { "match": { "first_name": "John" } } ] } } }

關於es的集群,雖說是主從配置,但是用起來,基本上不需要考慮這些問題,master,slave的切換是es內部處理的,對外面完全透明,可以用bigdesk插件查看;集群支持動態添加節點,和cassandra差不多,非常方便。

創建索引(數據庫)的時候,可以指定shards和replicas的數量,也可以動態修改replicas的數量,這對於需要橫向擴展的時候,非常有用。

 

貼一個大神的翻譯,非常感謝他的辛苦工作

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM