【发布时间】:2020-02-19 17:23:19
【问题描述】:
我希望使用 elasticsearch 在我的应用上实现类似自动完成的功能。
假设我的输入是"ronan f",我希望弹性返回姓氏或名字中包含"ronan" 或"f" 的所有元素。我希望 elasticsearch 按排名对结果进行排序,因此最接近我搜索的元素应该位于顶部。
我尝试了多个请求,但没有一个达到预期效果。
例如:
{
"query": {
"bool": {
"must_not": [
{
"match": {
"email": "*@guest.booking.com"
}
}
],
"should": [
{
"match": {
"lastname": "ronan"
}
},
{
"match": {
"firstname": "ronan"
}
},
{
"match": {
"lastname": "f"
}
},
{
"match": {
"firstname": "f"
}
}
],
"minimum_should_match" : 1
}
},
"sort": [
"_score"
],
"from": 0,
"size": 30
}
有了这个请求,队伍就有点奇怪了,例如:
"_index": "clients",
"_type": "client",
"_id": "4369",
"_score": 20.680058,
"_source": {
"firstname": "F",
"lastname": "F"
}
位于:
之上"_index": "clients",
"_type": "client",
"_id": "212360",
_score": 9.230003,
"_source": {
"firstname": "Ronan",
"lastname": "Fily"
}
对我来说,第二个结果应该比第一个有更好的排名。
谁能告诉我怎样才能达到我想要的结果?
关于信息,我无法使用 elasticsearch 的 Completion Suggester 功能,因为我无法访问数据库的配置(因此没有索引)。
【问题讨论】:
-
如果我们共享分析仪,您能否重新索引您的数据?
-
可能是的。如果我理解正确,elasticsearch 提供了创建多个分析器的可能性,这些分析器可以作为参数传递给查询,每个分析器都可以影响查询的结果。抱歉,这就像我使用 elasticsearch 的前 2 天,我需要找到一些学习教程。
-
@toto1911,你能解决这个问题吗?还是还在寻找答案?
-
是的,我设法在不使用新分析器的情况下优化我的请求,我将关闭帖子
标签: elasticsearch autocomplete elasticsearch-query