elasticsearch - Elasticsearch 前缀建议?
问题描述
如何通过前缀获得术语建议,我有名称字段。
我有三个记录:
坐在中间
完成最少的工作
运河 mib 不见了
当我输入min时,我希望能够将minimum一词作为建议的术语,但我确实得到了其他文档中的mid和mib 。
这是我的查询:
{
"suggest": {
"text": "min",
"simple_phrase": {
"term": {
"analyzer": "standard",
"field": "Name.raw",
"min_word_length": 2,
"prefix_length": 1,
"suggest_mode": "always"
}
}
}
}
映射:
{
"Name": {
"type": "text",
"index": "not_analyzed",
"include_in_all": true,
"fields": {
"raw": {
"type": "text",
"index": "not_analyzed",
"include_in_all": false
},
"trigram": {
"type": "text",
"analyzer": "trigram_analyzer"
}
}
}
}
结果
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": 0,
"hits": []
},
"suggest": {
"simple_phrase": [
{
"text": "min",
"offset": 0,
"length": 3,
"options": [
{
"text": "mib",
"score": 0.6666666,
"freq": 79
},
{
"text": "mid",
"score": 0.6666666,
"freq": 59
}
]
}
]
}
}
解决方案
正如它在文档中所说:
术语建议者根据编辑距离建议术语。在建议术语之前分析提供的建议文本。根据分析的建议文本标记提供建议的术语。术语建议者不考虑作为请求一部分的查询。
因此,术语建议者只是“编辑”您的文本。所以你可以尝试这样的事情,看看minimum
建议的结果:
{
"suggest": {
"text" : "minimam",
"simple_phrase" : {
"term" : {
"analyzer" : "standard",
"field" : "Name.raw",
"min_word_length" : 1,
"suggest_mode" : "always"
}
}
}
}
我认为,为了您的目的,最好使用完成建议器。
推荐阅读
- windows - Docker 设置和后端
- xml - 如何在 Android Studio 4.2 中使用新的 Basic Activity?
- javascript - 当触发它的页面关闭时,Javascript不会被触发
- omnet++ - 计算静脉中的 PSR 与 SNIR
- kotlin - 使用 Springdata JPA 的规范 API 获取枚举类型时获取 InvalidDataAccessApiUsageException
- c - 使用信号量时程序进入无限循环(死锁)
- laravel - 2个laravel项目交叉请求之间的问题
- c - 函数中的堆与函数参数重叠
- python - 从玩家那里得到输入后,猜数字游戏停止
- react-native - React Native - expo 构建 web 生产