【发布时间】:2019-10-17 16:26:22
【问题描述】:
我正在处理一个疯狂的需求,疯狂是因为我从未这样做过,而且从外观上看,我认为它不能直接完成。如果有人可以帮助我,请在此平台上寻求帮助。
如果值匹配,则要求在 Elasticsearch 中,然后我必须提供分数,但如果该字段存在但不匹配,则提供负分数,当后者相加时会降低分数。 示例假设我正在搜索两个字段名称和主题。如果名称匹配,则提供的分数为 50,如果主题匹配,则分数为 10。因此,如果两者都匹配,则得分为 60。如果主题不匹配,则得分为 -10,添加时得分为 40。
这在某些编程语言方面很容易,但在 Elasticsearch 查询中无法做到这一点。我正在使用函数评分,下面是示例查询。 感谢您在这方面的任何帮助。
GET dummy_rps_index_2/_search
{
"query": {
"bool": {
"must": [
{
"dis_max": {
"queries": [
{
"function_score": {
"boost_mode": "replace",
"score_mode": "max",
"max_boost": 100,
"query": {
"bool": {
"disable_coord": true,
"minimum_should_match": 1,
"should": [
{
"function_score": {
"score_mode": "max",
"boost_mode": "replace",
"_name": "name_match",
"query": {
"multi_match": {
"query": "TIFFIN",
"fields": [
"name"
],
"operator": "or",
"fuzziness": "AUTO"
}
},
"functions": [
{
"filter": {
"multi_match": {
"query": "TIFFIN",
"fields": [
"name"
],
"operator": "or",
"fuzziness": 0
}
},
"weight": 50
}
]
}
},
{
"function_score": {
"score_mode": "max",
"boost_mode": "replace",
"_name": "multipleline_code",
"query": {
"bool": {
"disable_coord": true,
"minimum_should_match": 1,
"should": [
{
"function_score": {
"boost_mode": "replace",
"query": {
"multi_match": {
"query": "maths",
"fields": [
"subject
]
}
},
"functions": [
{
"weight": 10
}
]
}
}
]
}
}
}
}
]
}
}
}
}
]
}
}
]
}
}
}
【问题讨论】:
标签: elasticsearch elastic-stack