失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 白话Elasticsearch22- 深度探秘搜索技术之match_phrase_prefix实现search-time搜索推荐

白话Elasticsearch22- 深度探秘搜索技术之match_phrase_prefix实现search-time搜索推荐

时间:2022-03-03 07:32:50

相关推荐

白话Elasticsearch22- 深度探秘搜索技术之match_phrase_prefix实现search-time搜索推荐

文章目录

概述match_phrase_prefix官方说明例子总结

概述

继续跟中华石杉老师学习ES,第22篇

课程地址: /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 worldhello wehello winhello windhello doghello cat

搜索 hello w

hello worldhello wehello winhello 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,搜索对应的docw,会作为前缀,去扫描整个倒排索引,找到所有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搜索推荐》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。