elasticsearch - 具有相邻单词的 Elastic Search 自动完成分析器
问题描述
在我的 ES 7.14 索引中,我在一些文本字段上设置了自定义分析器,如下所示:
{
"aliases": {},
"mappings": {
"properties": {
"text": {
"type": "text",
"analyzer": "autocomplete"
}
}
},
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "ngram",
"min_gram": 1,
"max_gram": 60
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
},
"index.max_ngram_diff": 60
}
}
sayt
此解决方案对于( search-as-you-type ) 之类的功能很有用,但在某些情况下,例如搜索相邻单词,这可能是个问题。事实上,当使用通配符时,*antonio* *banderas*
它可以按预期工作,但是当使用它时antonio banderas
,就像这里一样:
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"text": "antonio"
}
},
{
"wildcard": {
"text": "banderas"
}
}
]
}
}
}
由于自定义分析器autocomplete
绑定到字段text
,它将搜索包含antonio
plus的任何字符串(子标记) banderas
。另一个例子:搜索marq
会找到gabriel garcia marquez
,因为marq
in marquez
。marq
使用确切的通配符查询或*marq
没有尾随的.时不应发生这种情况*
。那么在这种情况下如何覆盖自动完成自定义分析器的行为来搜索相邻的单词呢?
解决方案
推荐阅读
- r - 如何根据R中的变量名提取列表中的列表
- visual-studio-code - 打开 VS Code 项目时执行一些命令
- angular - Angular - Ngx-org-chart 样式不起作用
- python - 将不同长度的数据帧导入mysql表
- ruby - 更新到 Ruby 3.0.1 后 Shotgun 无法启动
- codeigniter-4 - 升级 php 8 后无法运行 php spark serve
- regex - 正则表达式,如何在不排除第一行的情况下将字符串匹配成两组
- python - 我正在尝试从 DeepFaceLab 运行“3)从视频 data_dst FULL FPS.bat 中提取图像”,它只显示此消息
- video - ffmpeg如何用黑框/纯色结束视频
- python-3.x - Influxdb python 5.3.1 write_points不允许写入多行