elasticsearch常用命令

2022-06-29 02:57:19 字數 2120 閱讀 4584

目錄資料操作

資料查詢

參考鏈結

獲取es的基本資訊

curl localhost:9200
新建和刪除index

檢視當前節點的所有 index

curl -x get 'http://localhost:9200/_cat/indices?v'
建立乙個index
curl -x put 'localhost:9200/weather'
刪除乙個index
curl -x delete 'localhost:9200/weather'
資料操作

在index裡新增一條記錄

向指定的/index/type 發生put請求, /index/type/id, id 不一定是數字,也可以是任意的字串

curl -x put 'localhost:9200/accounts/person/1' -d '

'

不指定id, 新增一條記錄

注意這裡需要使用post請求,id是乙個隨機生成的字串

curl -x post 'localhost:9200/accounts/person' -d '

'

檢視一條記錄

/index/type/id ,url 的引數pretty=true表示以易讀的格式返回

curl 'localhost:9200/accounts/person/1?pretty=true'
刪除記錄
curl -x delete 'localhost:9200/accounts/person/1'
更新記錄
curl -x put 'localhost:9200/accounts/person/1' -d '

'

資料查詢

返回 index 下的所有type

返回/index/type下的所有記錄

curl 'localhost:9200/accounts/person/_search'

- took 表示該操作的耗時(單位為毫秒);

- timed_out表示是否超時;

- hits 表示命中的記錄;

-- total 表示返回記錄數;

-- max_score 表示最高的匹配程度;

-- hits 表示返回的記錄組成的陣列;

--- _score 表示匹配的程度,預設是按照這個字段降序排列;

全文搜尋
curl 'localhost:9200/accounts/person/_search'  -d '

}}'

上面**使用 match 查詢,指定的匹配條件是desc欄位裡面包含"軟體"這個詞;

elastic 預設一次返回10條結果,可以通過size欄位改變這個設定

curl 'localhost:9200/accounts/person/_search'  -d '

}, "size": 1

}'

如果有多個搜尋關鍵字,elasticsearch 認為它們是or關係

curl 'localhost:9200/accounts/person/_search'  -d '

}}'

上面**搜尋的是 軟體 or 系統

curl 'localhost:9200/accounts/person/_search'  -d '

}, }]}

}}'

如果要在多個欄位中搜尋同乙個關鍵字:

curl 'localhost:9200/accounts/person/_search'  -d '},}

]}

},"size": 2

}'

上面**是在字段"desc"和"title"中搜尋關鍵字"軟體"

參考鏈結

全文搜尋引擎 elasticsearch 入門教程

elasticsearch常用操作

es模板postman常用操作 類別方法 url描述 查詢模板get http ip 9200 template template 查詢模板中template開頭的所有模板 為萬用字元 查詢特定的模板get http ip 9200 template vias business查詢名為vias bu...

elastic search常用操作

常用操作 查詢所有索引及狀態 get cat indices?v 查詢productsearchuat索引,預設返回一條資料 get productsearchuat search 知道product id 查es索引 get productsearchuat search 通過企業名稱查詢企業 g...

elasticsearch常用curl鏈結

1 測試es是否啟動成功 pretty引數是為了讓查詢結果更方便閱讀 3 建立megacorp索引 employee型別 id為1的資料 索引名必須小寫,不能以下劃線開頭,不能包含逗號。型別命名可以是大寫或者小寫,但是不能以下劃線或者句號開頭,不應該包含逗號,並且長度限制為256個字元。如果該id的...