1. Elasticsearch配置說明
- 配置文件在config目錄
- elasticsearch.yml elasticsearch的相關配置
關鍵配置:
cluster.name 集羣名稱,以此作爲是否同一集羣的判斷條件
node.name 節點名稱,以此作爲集羣中不同節點的區分條件
network.host/http.port 網絡地址和端口,用戶http和transport服務使用
path.data 數據存儲地址
path.log 日誌存儲地址
Development與Production模式說明:
以transport的地址是否綁定在localhost爲判斷標準,network.host的配置
Development模式下在啓動時會以warning的方式提示配置檢查異常
Production模式下在啓動時會以error的方式提示配置檢查異常並退出
- jvm.options jvm的相關參數
-Xms1g # 根據自己的內存做出調整
-Xmx1g # 根據自己的內存做出調整 - log4j2.properties 日誌相關配置
- elasticsearch.yml elasticsearch的相關配置
2. Elasticsearch本地啓動集羣的方式
elasticsearch.bat
elasticsearch.bat -Ehttp.port=8200 -Epath.data=node2
elasticsearch.bat -Ehttp.port=7200 -Epath.data=node3
3. Elasticsearch常用API
http://localhost:9200/_cat/nodes?v 同一集羣下的所有節點
http://localhost:9200/_cluster/stats cluster相關信息
4. Elasticsearch常用術語
Document 文檔數據,具體存在Elasticsearch中的一條數據
Index 索引,可以理解爲mysql中的數據庫,所有的Document都存在具體的索引中
Type 索引中的數據類型,可以理解爲mysql中的table
Field 字段,文檔的屬性
Query DSL 查詢語法
5. Elasticsearch CRUD
Create 創建文檔
// hello -> index | world -> type | {所有數據內容} -> document | name/lastname/sex -> field POST /hello/world/1 { "name": "Tom", "lastname": "John", "sex": "male" }
Read 讀取文檔
GET /hello/world/1
Update 更新文檔
POST /hello/world/1/_update { "doc": { "sex": "female" } }
Delete 刪除文檔
DELETE /hello/world/1 DELETE /hello
6. Elasticsearch Query
- Query String
GET /hello/world/_search?q=tom
- Query DSL
GET /hello/world/_search { "query": { "match": { "name": "tom" } } }