你不会是程序猿吧?

请教各位大神:es2.X 搜索怎么使得搜索关键词越靠前,且占比越大的得分越高,排序越靠前

Elasticsearch | 作者 tianxuanchang | 发布于2020年01月10日 | 阅读数:1295

小白求指教,望各位大神不吝赐教
 
问题:es2.x  查询的时候,怎么使得搜索关键词越靠前,且占比越大的得分越高,排序越靠前。
 
例如:
      数据有如下疾病名称:高血压,糖尿病伴高血压,高血压伴糖尿病,原发性高血压
      想要效果:搜索‘高血压’,按照高血压三个字靠前,且占疾病名称总数占比比较大,搜出来的顺序是(1.高血压 2.高血压伴糖尿病3.原发性高血压 4.糖尿病伴高血压)
 
或者是不好同时实现,达到高血压在左边的排序靠前也可以。
已邀请:
使用fields创建一个不分词的field
PUT test
{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
}
}

POST test/doc/_mapping
{
"properties": {
"title": {
"type": "string",
"fields": {
"keyword": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}

POST test/doc/1
{
"title":"高血压"
}
POST test/doc/2
{
"title":"高血压伴糖尿病"
}
POST test/doc/3
{
"title":"原发性高血压"
}
POST test/doc/4
{
"title":"糖尿病伴高血压"
}
然后综合match和prefix查询:
POST test/doc/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "高血压"
}
},
{
"prefix": {
"title.keyword": {
"value": "高血压"
}
}
}
]
}
}
}
输出结果:
{
"took": 16,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1.1809239,
"hits": [
{
"_index": "test",
"_type": "doc",
"_id": "1",
"_score": 1.1809239,
"_source": {
"title": "高血压"
}
},
{
"_index": "test",
"_type": "doc",
"_id": "2",
"_score": 0.92702603,
"_source": {
"title": "高血压伴糖尿病"
}
},
{
"_index": "test",
"_type": "doc",
"_id": "3",
"_score": 0.15233879,
"_source": {
"title": "原发性高血压"
}
},
{
"_index": "test",
"_type": "doc",
"_id": "4",
"_score": 0.12694898,
"_source": {
"title": "糖尿病伴高血压"
}
}
]
}
}

tianxuanchang

赞同来自:

疾病名称使用了ik_smart分词器

God_lockin

赞同来自:

考不考虑用ES做召回,然后在内存里重排?这种区别打分的可能需要写script计算,但是会拖慢ES搜索的速度得不偿失

要回复问题请先登录注册