找到问题的解决办法了么?

suggest completion中的score是如何计算的?

Elasticsearch | 作者 lmc | 发布于2019年05月20日 | 阅读数:1727

官方文档的案例里score一直是1.0, 但我模仿官方文档,添加实例,设置权重,比如我的权重为10,但我的score却不是10,这个score说怎么计算的呢?
已邀请:

lmc

赞同来自:

我执行的请求顺序如下:(应该没有问题)1.生成测试用例 PUT test_suggest
PUT test_suggest
{
"mappings": {
"name" : {
"properties" : {
"suggest" : {
"type" : "completion",
"analyzer": "ik_smart"
}
}
}
}
}

POST test_suggest/name
{
"suggest" : {
"input": [ "阿里巴巴", "albb","alibaba" ],
"weight" : 34
}
}
POST test_suggest/name
{
"suggest" : {
"input": [ "百度", "bd","baidu" ],
"weight" : 10
}
}
2. 执行suggest查询
POST test_suggest/name/_search?search_type=dfs_query_then_fetch
{
"suggest": {
"my-suggest" : {
"prefix" : "百度",
"completion" : {
"field" : "suggest",
"size" : 50 ,
"fuzzy":{
"fuzziness":0
}
}
}
}
}
3.得到结果如下
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": 0,
"hits": []
},
"suggest": {
"my-suggest": [
{
"text": "百度",
"offset": 0,
"length": 2,
"options": [
{
"text": "百度",
"_index": "test_suggest",
"_type": "name",
"_id": "QRBe1GoBYDgG7DGxu69j",
"_score": 60,
"_source": {
"suggest": {
"input": [
"百度",
"bd",
"baidu"
],
"weight": 10
}
}
}
]
}
]
}
}
我使用的版本是6.7, 主要是想问问 这个score跟这个weight是什么关系, 怎么计算的?谢谢!
另外我是通过将拼音、全拼、中文都放入input来实习通过拼音完成自动补全的,但这样无法应用在拼音中文混合的情况下,比如输入“百du”, 大家有什么建议吗? 关于中文、拼音混合情况下的自动补全

God_lockin

赞同来自:

官网那个1分是用的这个数据
PUT xx/_doc/1
{
"suggest": [
"Nevermind",
"Nirvana"
]
}
你可以get出来看看,它的score或者说weight默认是1
GET xx/_doc/_search
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "music1",
"_type": "_doc",
"_id": "1",
"_score": 1,
"_source": {
"suggest": [
"Nevermind",
"Nirvana"
]
}
}
]
}
}
所以在做后面的suggest的query的时候
POST xx/_search
{
"suggest": {
"song-suggest": {
"prefix": "nir",
"completion": {
"field": "suggest"
}
}
}
}

{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": 0,
"hits": []
},
"suggest": {
"song-suggest": [
{
"text": "nir",
"offset": 0,
"length": 3,
"options": [
{
"text": "Nirvana",
"_index": "music1",
"_type": "_doc",
"_id": "1",
"_score": 1,
"_source": {
"suggest": [
"Nevermind",
"Nirvana"
]
}
}
]
}
]
}
}

lailai - 我一无所有

赞同来自:

中文:搜索词的汉字个数 * 3 * weight (如果没有设置weight,则默认是1) + (分词个数-1)
英文:搜索词的字符个数 * 1 * weight (如果没有设置weight,则默认是1) 

要回复问题请先登录注册