elasticsearch - Elasticsearch 自动完成拼写错误
问题描述
我正在尝试创建具有与Apollo graphql类似的功能的自动完成功能。基本上它:
- 在我输入时搜索
- 处理错别字
- 最重视标题,然后是子标题,最后是内容
虽然在 Apollo graphql doc 中这个功能是由 algolia 提供的,但我很确定我可以用 elasticsearch 构建它。
我从Search-as-you-type 字段类型开始,并轻松使其按如下方式工作。
映射:
PUT /article
{
"mappings": {
"properties": {
"title": {
"type": "search_as_you_type"
}
}
}
}
一些虚拟数据:
PUT /article/_bulk
{ "index": {"_id": "1"} }
{ "title": "Authentication and authorization", "subtitle": "Putting authenticated user info on the context" }
并搜索:
GET /article/_search
{
"query": {
"multi_match": {
"query": "auth",
"type": "bool_prefix",
"fuzziness" : "AUTO",
"prefix_length" : 2,
"fields": [
"title",
"title._2gram",
"title._3gram",
"title._index_prefix"
]
}
}
}
现在我能够得到以下信息:
a -> Authentication and authorization
au -> Authentication and authorization
aut -> Authentication and authorization
...
但是当我把一个词拼错到autentication
ES 时,什么也没有返回。
经过一些研究,我发现它fuzziness
不适用于bool_prefix
. 看:
- https://github.com/elastic/elasticsearch/issues/56229
- https://discuss.elastic.co/t/fuzziness-not-work-with-bool-prefix-multi-match-search-as-you-type/229602/3
那么请有其他方法来实现这种期望的行为吗?还是elasticsearch技术只是无法实现这个功能?
解决方案
推荐阅读
- javascript - 光滑的多个类相同的功能 - 寻找最佳解决方案
- javascript - 渲染threeJs渲染器列表的问题
- c# - 在 ASP.NET Core 中使用证书身份验证调用 WCF 服务,而不使用传输安全模式
- c++ - 图片上的文字
- json - 如何在 VSCode 设置中设置 Prettier 以按文件类型有条件地应用单引号?
- android - 无法在 Kotlin 中使用 Retrofit TypeAdapter 将 Gson Doubles 舍入为 Longs
- java - 是否可以在 Spring Boot 中停止打印 AmqpRejectAndDontRequeueException 堆栈跟踪日志?
- python - 将元组出现转换为数据框列中的字符串
- mysql - 无法连接本地数据库。Sequel Pro 遇到意外错误
- java - Hibernate-Search - 使用 lucene 查询解析器语法不区分大小写的通配符搜索(不使用 QueryBuilder!)