我在Elastic Search上有一个这样的Map
{
mappings: {
properties: {
score: { type: 'double' },
name: { type: 'search_as_you_type' }
}
}
}
和如下所示的查询
{
sort: [{ score: 'asc' }, '_score'],
query: {
multi_match: {
query: text,
type: 'bool_prefix',
fields: [
'name',
'name._2gram',
'name._3gram',
]
}
}
}
我们的目标是有“名称”的自动补全功能按“分数”从名称的开头开始排序。
因此,如果搜索文本是“goo”,则应该匹配“google.com”,而不是“mail.google.com”。
现在它似乎同时完成前缀和中缀补全,我如何才能将其限制为前缀补全呢?
1条答案
按热度按时间bxjv4tth1#
现在官方文件中有一节描述了这一点。您可以使用
search_as_you_type
Map上的根字段来实现这一点,我认为您的用例应该是这样的: