ElasticSearch多種搜尋方式

2021-09-27 01:18:56 字數 2046 閱讀 1765

一,query string search 搜尋

get

/ecommerce/product/_search

搜尋商品名稱中包含牙膏的商品,而且按售價降序排序:

get

/ecommerce/product/_search?q=name:yagao&sort=price:desc

適用於臨時的在命令列使用一些工具,比如curl,快速的發出請求,來檢索想要的資訊,但是如果查詢請求很複雜,是很難去構建的 在生產環境中,幾乎很少使用

query string search took:耗費了幾毫秒

time_out:是否超時

_shards:由於把資料拆成了5個分片,所以對於搜尋請求,會打到所有的primary shard(或者是它的某個replica shard也可以)

hits.total:查詢結果的數量,幾個document

hits.max_score:score 就是document對於乙個search的相關度的匹配分數,越相關,就越匹配,分數也高 hits.hits:包含了匹配搜尋的document的詳細資料

二,query dsl

dsl(domain specifies langguage)特定領域的語言 http request body:請求體,可以用json的格式來構建查詢語言,比較方便,可以構建各種複雜的語法,比query string search

get

/ecommerce/product/_search

}}

查詢名稱包含yagao的商品,同時按照**降序排序

get

/ecommerce/product/_search },

"sort":[

]}

分頁查詢商品,總共三條商品,假設每頁就顯示一條商品,現在顯示第二頁,所以就查出來 第二個商品

get

/ecommerce/product/_search },

"from":1

,"size":2

}

指定要查詢出來商品的名稱和**就可以

get

/ecommerce/product/_search},

"_source":[

"name"

,"price"

]}

更加適合生產環境的使用,可以構建複雜的查詢

三,query filter 搜尋

商品名稱包含yagao,而且售價大於25元的商品

get

/ecommerce/product/_search },

"filter":}

}}}}

四,full-text search (全文檢索)
get

/ecommerce/product/_search

}}

producer這個字段,會先被拆解,建立倒排索引

special 4

yagao 4

producer 1 2 3 4

gaolujie 1

zhonghua 3

jiajieshi 2

當 yagao producer---->yagao和producer

五,phrase search(短語搜尋)

跟全文檢索相反,全文檢索會將輸入的搜尋串拆解開來,去倒排索引裡面去一一匹配,只要能匹配上任意乙個拆解後的單詞,就可以作為結果返回 phrase search:要求輸入的搜尋串,必須在指定的字段文字中,完全包含一模一樣的,才可以算是匹配,才能作為結果返回。

get

/ecommerce/product/_search

}}

六,highlight search (高亮搜尋)
get

/ecommerce/product/_search },

"highlight":}

}}

Elasticsearch多種查詢示例

版本 6.8.1 目前es的6.x與7.x都在同步維護著。put hyomin put category images price saleable stock title 插入資料 查詢資料準備 post hyomin goods bulk 匹配查詢 match 1.查詢所有 get hyomin...

git多種操作

剛開始我git remote add origin錯了位址,寫成http的位址了,然後就git remote rm origin了,重新git remote add origin git github.com lxgithub24 opensns.git 就可以了。之後git push u orig...

多種排序組合

include void bubble int a,int n 氣泡排序 void choise int a,int n 選擇排序 void quick int a,int i,int j 快速排序 void insert int a,int n 插入法 void shell int a,int n...