文章目录

  • 概述
  • 官网
  • 什么是ngram
  • 什么是edge ngram
  • ngram和index-time搜索推荐原理
  • 例子

概述

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

课程地址: https://www.roncoo.com/view/55


官网

NGram Tokenizer:
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html

NGram Token Filter:
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenfilter.html


Edge NGram Tokenizer:
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenizer.html

Edge NGram Token Filter:
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenfilter.html


什么是ngram

什么是ngram

假设有个单词quick,5种长度下的ngram

ngram length=1,会被拆成 q u i c k
ngram length=2,会被拆成 qu ui ic ck
ngram length=3,会被拆成 qui uic ick
ngram length=4,会被拆成 quic uick
ngram length=5,会被拆成 quick

其中任意一个被拆分的部分 就被称为ngram 。


什么是edge ngram

quick,anchor首字母后进行ngram

q
qu
qui
quic
quick

上述拆分方式就被称为edge ngram


使用edge ngram将每个单词都进行进一步的分词切分,用切分后的ngram来实现前缀搜索推荐功能

举个例子 两个doc
doc1 hello world
doc2 hello we

使用edge ngram拆分

h
he
hel
hell
hello -------> 可以匹配 doc1,doc2

w -------> 可以匹配 doc1,doc2
wo
wor
worl
world
e ---------> 可以匹配 doc2

使用hello w去搜索

hello --> hello,doc1
w --> w,doc1

doc1中hello和w,而且position也匹配,所以,ok,doc1返回,hello world


ngram和index-time搜索推荐原理

搜索的时候,不用再根据一个前缀,然后扫描整个倒排索引了,而是简单的拿前缀去倒排索引中匹配即可,如果匹配上了,那么就好了,就和match query全文检索一样


例子

PUT /my_index
{"settings": {"analysis": {"filter": {"autocomplete_filter": { "type":     "edge_ngram","min_gram": 1,"max_gram": 20}},"analyzer": {"autocomplete": {"type":      "custom","tokenizer": "standard","filter": ["lowercase","autocomplete_filter" ]}}}}
}

helloworld
设置

min ngram = 1
max ngram = 3

使用edge_ngram ,则会被拆分为一下 ,

h
he
hel


知识点: autocomplete

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html


GET /my_index/_analyze
{"analyzer": "autocomplete","text": "helll world"
}

设置mapping , 查询的时候还是使用standard

PUT /my_index/_mapping/my_type
{"properties": {"title": {"type":     "text","analyzer": "autocomplete","search_analyzer": "standard"}}
}

造数据

PUT /my_index/my_type/1
{"content":"hello Jack"
}PUT /my_index/my_type/2
{"content":"hello John"
}PUT /my_index/my_type/3
{"content":"hello Jose"
}

查询

GET /my_index/my_type/_search
{"query": {"match": {"content": "hello J"}}
}

返回:

{"took": 7,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 3,"max_score": 0.2876821,"hits": [{"_index": "my_index","_type": "my_type","_id": "2","_score": 0.2876821,"_source": {"content": "hello John"}},{"_index": "my_index","_type": "my_type","_id": "1","_score": 0.2876821,"_source": {"content": "hello Jack"}},{"_index": "my_index","_type": "my_type","_id": "3","_score": 0.2876821,"_source": {"content": "hello Jose"}}]}
}
  • 如果用match,只有hello的也会出来,全文检索,只是分数比较低
  • 推荐使用match_phrase,要求每个term都有,而且position刚好靠着1位,符合我们的期望的

白话Elasticsearch23-深度探秘搜索技术之通过ngram分词机制实现index-time搜索推荐相关推荐

  1. 23_ElsaticSearch 搜索推荐ngram分词机制实现index-time

    23_ElsaticSearch 搜索推荐ngram分词机制实现index-time 更多干货 分布式实战(干货) spring cloud 实战(干货) mybatis 实战(干货) spring ...

  2. 白话Elasticsearch13-深度探秘搜索技术之基于multi_match+most fields策略进行multi-field搜索

    文章目录 概述 官网 示例 构造模拟数据 普通查询 使用 multi_match + most fileds查询 best fields VS most fields 概述 继续跟中华石杉老师学习ES ...

  3. 白话Elasticsearch15-深度探秘搜索技术之使用copy_to定制组合field解决cross-fields搜索弊端

    文章目录 概述 官网 例子 总结 概述 继续跟中华石杉老师学习ES,第15篇 课程地址: https://www.roncoo.com/view/55 官网 https://www.elastic.c ...

  4. 程序员业务,微信全文搜索技术优化

    一.iOS微信全文搜索技术的现状 全文搜索是使用倒排索引进行搜索的一种搜索方式.倒排索引也称为反向索引,是指对输入的内容中的每个Token建立一个索引,索引中保存了这个Token在内容中的具体位置.全 ...

  5. 微信全文搜索技术优化

    一.iOS 微信全文搜索技术的现状 全文搜索是使用倒排索引进行搜索的一种搜索方式.倒排索引也称为反向索引,是指对输入的内容中的每个Token建立一个索引,索引中保存了这个Token在内容中的具体位置. ...

  6. 白话Elasticsearch27-深度探秘搜索技术之误拼写时的fuzzy模糊搜索技术

    文章目录 概述 官方指导 例子 推荐写法 概述 继续跟中华石杉老师学习ES,第27篇 课程地址: https://www.roncoo.com/view/55 官方指导 https://www.ela ...

  7. 白话Elasticsearch14-深度探秘搜索技术之基于multi_match 使用most_fields策略进行cross-fields search弊端

    文章目录 概述 官网 示例 概述 继续跟中华石杉老师学习ES,第十四篇 课程地址: https://www.roncoo.com/view/55 官网 https://www.elastic.co/g ...

  8. 白话Elasticsearch08-深度探秘搜索技术之基于boost的细粒度搜索条件权重控制

    文章目录 概述 boost 示例 概述 继续跟中华石杉老师学习ES,第八篇 课程地址: https://www.roncoo.com/view/55 boost https://www.elastic ...

  9. Elasticsearch深度探秘搜索技术如何手动控制全文检索结果的精准度

    为帖子数据增加标题字段 #插入数据 POST /post/_doc/_bulk { "update": { "_id": "1"} } { ...

最新文章

  1. jlink的SWD与JTAG下载模式的对应接线方法
  2. mysql菜鸟教程update_PHP MySQL Update
  3. 【Python-ML】集成多数投票分类器-训练评估调优
  4. 判断一个变量类型是数组还是对象
  5. 实例讲解如何通过Oracle成功发送邮件-入门基础
  6. C/C++中调用api设置mysql连接的编码方式
  7. matlab谐波仿真代码,matlab的谐波仿真程序基于ip-iq法???怎么出不来图像啊???...
  8. JedisConnectionException: java.Net.SocketTimeoutException: Read timed
  9. 网易java默认路径_java对象存储位置
  10. 网络工程师考试2005年上半年下午试题解析(二)
  11. mysql删除表单挑数据_MySQL 删除数据表
  12. [转载] 蓝胡子国王的金钥匙
  13. 转载:相同版本的JVM和Java应用,在 x86 和AArch64 平台性能相差30%
  14. (转)“不开心”的10种英语表达
  15. 计算机网络路由器的配置连接不上,路由器安装设置好后电脑还是不能上网解决办法...
  16. 360极速浏览器的兼容模式
  17. crash _mach_msg_trap
  18. PS学习-人像照片综合处理(二)--祛斑/祛痘与磨皮综合处理
  19. 【C++】2048游戏系列---优化模块第一稿【加载图片】
  20. 资产监测技术中关于USIM卡座在PCB layut设计中注意事项浅谈

热门文章

  1. ubuntu spyder 不能输入中文
  2. word2vect 输出是什么
  3. 76. Leetcode 295. 数据流的中位数 (堆-技巧一-固定堆)
  4. 推荐系统笔记(评价指标及效果)
  5. 论文笔记 Spectral Regularization Algorithms for Learning Large IncompleteMatrices (soft-impute)
  6. 深度学习核心技术精讲100篇(三十七)-利用Contrastive Learning对抗数据噪声:对比学习在微博场景的实践
  7. Linux中的通配符
  8. python把图片另存为_pycharm sciview的图片另存为操作
  9. 计算机科学和机器学习中的代数学、拓扑学、微积分以及最优化理论
  10. 算法工程师和算法框架开发,谁会代表未来?