白话Elasticsearch22- 深度探秘搜索技术之match_phrase_prefix实现search-time搜索推荐
生活随笔
收集整理的這篇文章主要介紹了
白话Elasticsearch22- 深度探秘搜索技术之match_phrase_prefix实现search-time搜索推荐
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 概述
- match_phrase_prefix
- 官方說明
- 例子
- 總結
概述
繼續跟中華石杉老師學習ES,第22篇
課程地址: https://www.roncoo.com/view/55
match_phrase_prefix
官方說明
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html
搜索推薦,search as you type,搜索提示,解釋一下什么意思
假設有這么幾個doc 如下
hello world hello we hello win hello wind hello dog hello cat搜索 hello w
hello world hello we hello win hello wind會給出提示 如何上 ,搜索推薦的功能
這種效果
例子
造點數據
PUT /my_index1/my_type1/1 {"content":"hello Jack" }PUT /my_index1/my_type1/2 {"content":"hello John" }PUT /my_index1/my_type1/3 {"content":"hello Jose" }PUT /my_index1/my_type1/4 {"content":"hello Dave" }查詢
GET /my_index1/my_type1/_search {"query": {"match_phrase_prefix": {"content": "hello J"}} }返回
{"took": 38,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 3,"max_score": 1.7509375,"hits": [{"_index": "my_index1","_type": "my_type1","_id": "2","_score": 1.7509375,"_source": {"content": "hello John"}},{"_index": "my_index1","_type": "my_type1","_id": "1","_score": 1.1507283,"_source": {"content": "hello Jack"}},{"_index": "my_index1","_type": "my_type1","_id": "3","_score": 1.1507283,"_source": {"content": "hello Jose"}}]} }總結
match_phrase_prefix原理跟match_phrase類似,唯一的區別,就是把最后一個term作為前綴去搜索
- hello就是去進行match,搜索對應的doc
- w,會作為前綴,去掃描整個倒排索引,找到所有w開頭的doc
- 然后找到所有doc中,即包含hello,又包含w開頭的字符的doc
- 根據你的slop去計算,看在slop范圍內,能不能讓hello w,正好跟doc中的hello和w開頭的單詞的position相匹配
- 也可以指定slop,但是只有最后一個term會作為前綴
- max_expansions:指定prefix最多匹配多少個term,超過這個數量就不繼續匹配了,限定性能
- 默認情況下,前綴要掃描所有的倒排索引中的term,去查找w打頭的單詞,但是這樣性能太差。可以用max_expansions限定,w前綴最多匹配多少個term,就不再繼續搜索倒排索引了。
盡量不要用,因為,最后一個前綴始終要去掃描大量的索引,性能可能會很差
總結
以上是生活随笔為你收集整理的白话Elasticsearch22- 深度探秘搜索技术之match_phrase_prefix实现search-time搜索推荐的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 白话Elasticsearch20-深度
- 下一篇: 白话Elasticsearch23-深度