ElasticSearch入門-基本概念介紹以及安裝

Elasticsearch基本概念

Elasticsearch是基於Lucene的全文檢索庫,本質也是存儲數據,很多概念與傳統關係型數據庫類似。

傳統關係型數據庫與Elasticsearch進行概念對比

Elasticsearch 傳統關係型數據庫
indices(索引庫) Databases(數據庫)
type(類型) Table(數據表)
Document(文檔) Row(行)
Field(字段) Columns(列)
mappings(映射配置) 表結構

具體說明

概念 具體說明
indices(索引庫) indices是index的複數,代表許多的索引
type(類型) 類型是模擬傳統關係型數據庫中的table概念,一個索引庫下可以有不同類型的索引,比如商品索引,訂單索引,其數據格式不同。不過這會導致索引庫混亂,因此未來版本中會移除這個概念
Document(文檔) 存入索引庫原始的數據。比如每一條商品信息,就是一個文檔
Field(字段) 文檔中的屬性
mappings(映射配置) 字段的數據類型、屬性、是否索引、是否存儲等特性
索引集(Indices,index的複數) 邏輯上的完整索引
分片(shard) 數據拆分後的各個部分
副本(replica) 每個分片的複製

注:Elasticsearch本身就是分佈式的,因此即便你只有一個節點,Elasticsearch默認也會對你的數據進行分片(默認5個分片)和副本操作,當你向集羣添加新數據時,數據也會在新加入的節點中進行平衡。

安裝Elasticsearch和ik分詞器

安裝前需要配置JAVA環境

Mac

安裝Elasticsearch

homebrew安裝

brew install elasticsearch

運行

  • 查看狀態

    $ brew services list

  • 啓動

    $ brew services start elasticsearch

  • 重啓

    $ brew services restart elasticsearch

  • 停止

    $ brew services stop elasticsearch

瀏覽器輸入 http://localhost:9200 查看ES是否運行

你也可以打開終端,執行以下操作:

curl 'http://localhost:9200/?pretty'

最終的響應結果和下面類似:

{
  "name": "pYaFJhZ",
  "cluster_name": "docker-cluster",
  "cluster_uuid": "oC28y-cNQduGItC7qq5W8w",
  "version": {
    "number": "6.8.2",
    "build_flavor": "oss",
    "build_type": "tar",
    "build_hash": "b506955",
    "build_date": "2019-07-24T15:24:41.545295Z",
    "build_snapshot": false,
    "lucene_version": "7.7.0",
    "minimum_wire_compatibility_version": "5.6.0",
    "minimum_index_compatibility_version": "5.0.0"
  },
  "tagline": "You Know, for Search"
}

安裝ik分詞器

終端下安裝:

$ cd /usr/local/Cellar/elasticsearch/ES版本

$ bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.2/elasticsearch-analysis-ik-6.8.2.zip

install後邊的地址爲ES對應版本的ik分詞器的下載地址

Windows

安裝Elasticsearch

下載安裝包,解壓,然後雙擊執行 bin/elasticsearch.bat進行安裝。

運行

命令提示符

elasticsearch.bat -d

或者直接雙擊執行elasticsearch.bat

瀏覽器輸入 http://localhost:9200 查看ES是否運行。

或者下載cURL(點此下載),使用cURL的方式驗證:

curl 'http://localhost:9200/?pretty'

安裝ik分詞器

命令提示符下安裝:

\bin\elasticsearch-plugin.bat install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.2/elasticsearch-analysis-ik-6.8.2.zip

注:

  1. 安裝完ik分詞器之後需要重啓ES
  2. Elasticsearch版本和elasticsearch-analysis-ik需要一一對應!

Elasticsearch配置文件elasticsearch.yml

配置參數 介紹
cluster.name 集羣名稱,默認是elasticsearch
node.name 節點名,稱默認從elasticsearch-2.4.3/lib/elasticsearch-2.4.3.jar!config/names.txt中隨機選擇一個名稱
path.data 指定es的數據存儲目錄,默認存儲在es_home/data目錄下
path.logs 指定es的日誌存儲目錄,默認存儲在es_home/logs目錄下
bootstrap.memory_lock 鎖定物理內存地址,防止elasticsearch內存被交換出去,也就是避免es使用swap交換分區
network.host 爲es設置ip綁定,默認是127.0.0.1,也就是默認只能通過127.0.0.1 或者localhost才能訪問
http.port 爲es設置自定義端口,默認是9200(在同一個服務器中啓動多個es節點的話,默認監聽的端口號會自動加1:例如:9200,9201,9202...)
discovery.zen.ping.unicast.hosts 當啓動新節點時,通過這個ip列表進行節點發現,組建集羣默認節點列表: ["127.0.0.1", "[::1]"] 127.0.0.1:表示ipv4的迴環地址。 [::1]:表示ipv6的迴環地址
discovery.zen.minimum_master_nodes 通過配置這個參數來防止集羣腦裂現象 (集羣總節點數量/2)+1
gateway.recover_after_nodes 一個集羣中的N個節點啓動後,才允許進行數據恢復處理,默認是1
action.destructive_requires_name 設置是否可以通過正則或者_all刪除或者關閉索引庫,默認true表示必須需要顯式指定索引庫名稱

本文鏈接:https://www.lifengdi.com/archives/article/tech/869

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章