elasticsearch 權威指南入門閱讀筆記(一)
什麽是elasticsearch
elasticsearch是java基礎apache lucene的開源搜索引擎,開箱即用,elasticsearch有很多默認的合理的配置
elasticsearch作用
全文檢索,分布式實時文件存儲,分布式實時分析引擎,可以擴展到上百臺服務器處理PB級結構化數據或非結構化數據
elasticsearch安裝
官網下載:https://www.elastic.co/downloads/elasticsearch解壓
linux運行:./bin/elasticsearch
訪問:http://localhost:9200/?pretty
表示安裝成功
ES與傳統數據的區別
關系型數據庫:databases->tables->rows->columns
ES:indices->types->documents->Fileds
index可以理解成數據庫 type可以理解為表 doument可以理解為行 filed可以理解為列
索引名詞=數據庫 索引動詞可以理解為數據庫的insert語句 索引文檔如果存在 舊的將覆蓋新的 ES為字段建立的索引為倒排索引
建立索引
現在我們建立1個產品的索引(insert)
posman put請求
http://127.0.0.1:9200/opcmdev/product/1
body:
{ "productName": "法瑞思 天然椰棕床墊棕墊硬床墊定做 薄乳膠棕櫚榻榻米床墊定制折疊1.2/1.5/1.8", "price": "10", "remark": "不錯的床墊", "tags": ["家具", "床墊", "棉花
我們可以理解為在opcmdev數據庫 product表 插入了一條產品信息 方便後面測試 多添加幾條數據
http://127.0.0.1:9200/opcmdev/product/2
{ "productName": "南極人(Nanjiren)床墊家紡 加厚立體床墊羽絲絨床墊床褥子學生宿舍","price": "109", "remark": "不錯的床墊", "tags": ["家具", "床墊", "棉花被"] }
http://127.0.0.1:9200/opcmdev/product/3
{ "productName": "¥99.00誌高(CHIGO)電火鍋家用多功能電炒鍋電煮鍋不粘多用途鍋電熱鍋 ZG-RH2", "price": "99", "remark": "平底鍋", "tags": ["電器", "平底鍋"] }
檢索文檔(查詢)
根據id查詢
get請求:http://127.0.0.1:9200/opcmdev/product/3
不帶條件的簡單搜索
get請求:http://127.0.0.1:9200/opcmdev/product/_search 默認返回前10條
{ "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 3, "max_score": 1, "hits": [ { "_index": "opcmdev", "_type": "product", "_id": "2", "_score": 1, "_source": { "productName": "南極人(Nanjiren)床墊家紡 加厚立體床墊羽絲絨床墊床褥子學生宿舍", "price": "109", "remark": "不錯的床墊", "tags": [ "家具", "床墊", "棉花被" ] } }, { "_index": "opcmdev", "_type": "product", "_id": "1", "_score": 1, "_source": { "productName": "法瑞思 天然椰棕床墊棕墊硬床墊定做 薄乳膠棕櫚榻榻米床墊定制折疊1.2/1.5/1.8", "price": "10", "remark": "不錯的床墊", "tags": [ "家具", "床墊", "棉花被" ] } }, { "_index": "opcmdev", "_type": "product", "_id": "3", "_score": 1, "_source": { "productName": "¥99.00誌高(CHIGO)電火鍋家用多功能電炒鍋電煮鍋不粘多用途鍋電熱鍋 ZG-RH2", "price": "99", "remark": "平底鍋", "tags": [ "電器", "平底鍋" ] } } ] } }
通過url?q模糊搜索
http://127.0.0.1:9200/opcmdev/product/_search?q=productName:鍋
elasticsearch 權威指南入門閱讀筆記(一)