1. ES倒排索引
給每個詞指定編號,記錄熱詞所在的文檔編號
ES底層分詞就是這種格式
數據庫使用的是B-tree的結構
正排索引:通過key找value
倒排索引:通過value找key
2. ES 9200與9300的區別
9200是與外部通信的接口,支持restful web接口,http協議
9300是ES內部,分佈式節點,高可用節點間通信的接口,TCP協議
3. 高級檢索
GET、PUT,/索引/類型/_serarch?age>10&&age<21
4. DSL,檢索term 與,match的區別
發送post請求,請求格式使用json格式
term是精確匹配
match是模糊匹配。
filter是對搜索結果進行過濾
“_source”:[ "X", "Y"] 指定顯示搜索結果的那些字段
搜索時必須使用“query”關鍵字
5. IK中文分詞插件
ES自帶的是標準分詞器,但是對中文的支持不友好,總是被中分按照每次字去拆分。
IK-smart,支持中文,並且會去網上查找熱詞。
6. 自定義熱詞
在plus/conf/目錄下創建自定義文件,添加自定義熱詞,然後讓插件加載此文件
7. luence, 分詞搜索引擎工具包
是個開源的工具包
8. text與keyword的區別
text類型支持分詞
keyword類型是不支持分詞的
9. ES是分佈式多用戶的搜索引擎
10. ES的架構設計
gateway-->luence dir-->river、mapping、search 、index--->discover 、script -->transport--->restful api
11. ES的設計原理
核心是index
從下向index: 爬取內容-->構建文檔-->分析文檔-->索引文檔-->索引
從上向index: 用戶查詢接口--->構建 query-->運行query
12. mapping
文檔結構映射,動態映射,靜態映射
動態映射:會根據數據自定義mapping, 將整形指定爲long類型
靜態映射:在添加數據前,先構建表結構
13. ELK
elasticsearch,---存儲,查詢,
logstash --- 數據轉儲
kibana --- 可視化工具
14. 冪等操作
同一操作不管重複幾次,結果都是一樣的。
15. POST與PUT
POST是作用在組合之上
curl http://localhost:9200/usr/ -d '{"age":20, "name":"小軍"}'
PUT是作用在具體資源
curl http://localhost:9200/usr/1 -d '{"age":20, "name":"小藍"}'
查詢
16. pretty作用
es可以得到易於識別的json結果
17._source字段可以指定要顯示的字段
root@RealEyeServerITS:~# curl -XGET 'http://localhost:9200/testes/user/1?_source=age&pretty'| jq .
{
"_index" : "testes",
"_type" : "user",
"_id" : "1",
"_version" : 4,
"found" : true,
"_source" : {
"age" : 20
}
}
18. 查詢指定類型的所有數據
curl -XGET 'http://localhost:9200/testes/user/_search' | jq .
19. 指定查詢條件
curl -XGET 'http://localhost:9200/testes/user/_search?q=age:20' | jq .
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "testes",
"_type": "user",
"_id": "AXFDbuNbamoZeUigoHG7",
"_score": 1,
"_source": {
"age": 20,
"name": "小軍"
}
},
{
"_index": "testes",
"_type": "user",
"_id": "1",
"_score": 1,
"_source": {
"age": 20,
"name": "小軍"
}
}
]
}
}
DSL查詢
1. _mget可以查詢多個文件
使用數組設置查詢條件
2. ids的使用
如果在同一索引,同一類型中
3. XHEAD查找文檔是否存在
root@RealEyeServerITS:~# curl -i -XHEAD http://localhost:9200/testes/user/1?pretty
Warning: Setting custom HTTP method to HEAD with -X/--request may not work the
Warning: way you want. Consider using -I/--head instead.
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 156
更新
1. _update
將舊數據改爲刪除狀態,插入新數據,後臺刪除舊數據
curl -XPOST http://localhost:9200/testes/user/1/_update -d '{"doc":{"age":12, "name":"xiaohong"}}'
批量操作_bulk
可以將數據寫入json文件 ,http最大請求內容100mb
2. 查看集羣狀態
curl -XGET http://localhost:9200/_cluster/health?pretty
3. 分片數量
分佈式搜索提高性能和吞吐量
4. gateway
索引的持久化方式
5. discovery
es節點自動發現節點方式,廣播方式,多播協議
6. transport(核心)
內部節點交互方式。通過tcp的http協議,還有其他方式(插件)
7. 主版本,此版本
8.詞分析過程
空格分析器-->詞分割器-->大寫變小寫-->index
9. 停用詞
分析文檔過程中,把“的,着,了”這些詞認爲是停用詞。