关于文档的基本操作---ElasticSearch
生活随笔
收集整理的這篇文章主要介紹了
关于文档的基本操作---ElasticSearch
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
關于文檔的基本操作(重點)
基本操作
添加數據
PUT /psz/user/1 {"name": "psz","age": 22,"desc": "偶像派程序員","tags": ["暖","帥"] }獲取數據
GEt psz/user/1 ===============輸出=========== {"_index" : "psz","_type" : "user","_id" : "1","_version" : 1,"_seq_no" : 0,"_primary_term" : 1,"found" : true,"_source" : {"name" : "psz","age" : 22,"desc" : "偶像派程序員","tags" : ["暖","帥"]} }更新數據PUT
更新數據,推薦POST _update
- 不推薦
- 推薦!
簡單搜索 GET
GET psz/user/1簡答的條件查詢:根據默認映射規則產生基本的查詢
GET psz/user/_search?q=name:龐世宗復雜查詢
查詢,參數使用JSON體
GET psz/user/_search {"query": {"match": {"name": "龐世宗" //根據name匹配} },"_source": ["name","age"], //結果的過濾,只顯示name和age"sort": [{"age": {"order": "desc" //根據年齡降序}}],"from": 0, //分頁:起始值,從0還是"size": 1 //返回多少條數據 }- 之后只用java操作es時候,所有的對象和方法就是這里面的key
- 分頁前端 /search/{current}/{pagesize}
布爾值查詢
must(對應mysql中的and) ,所有條件都要符合
GET psz/user/_search {"query": {"bool": {"must": [ //相當于and{"match": {"name": "龐世宗"}},{"match": {"age": 22}}]}} }shoule(對應mysql中的or)
GET psz/user/_search {"query": {"bool": {"should": [ //should相當于or{"match": {"name": "龐世宗"}},{"match": {"age": 22}}]}} }must_not (對應mysql中的not)
過濾器
GET psz/user/_search {"query": {"bool": {"should": [{"match": {"name": "龐世宗"}}],"filter": [{"range": {"age": {"gt": 20 //過濾年齡大于20的}}}]}} }多條件查詢
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-bmL2gesJ-1610955698825)(C:\Users\王東梁\AppData\Roaming\Typora\typora-user-images\image-20210117233812605.png)]
精確查詢
- trem查詢是直接通過倒排索引指定的詞條進行精確的查找的。
關于分詞:
trem,直接查詢精確地
match,會使用分詞器解析
關于類型:
text: 分詞器會解析
keywords: 不會被拆分
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-rTBEDylJ-1610955698826)(C:\Users\王東梁\AppData\Roaming\Typora\typora-user-images\image-20210117234310173.png)]
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-YUZ64FCL-1610955698827)(C:\Users\王東梁\AppData\Roaming\Typora\typora-user-images\image-20210117234442418.png)]
高亮查詢
GET psz/user/_search {"query": {"match": {"name": "龐世宗"}},"_source": ["name","age"],"sort": [{"age": {"order": "desc"}}],"highlight": //高亮{"pre_tags": "<P>", //自定義高亮"post_tags": "</P>", "fields": {"name":{} //自定義高亮區域} } }總結
以上是生活随笔為你收集整理的关于文档的基本操作---ElasticSearch的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Rest风格---ElasticSear
- 下一篇: ElasticSearch(笔记)