我想使用单个ElasticSearch查询进行此类排序(无需使用script_score):
起初,我以为我可以做一个function_score查询(boost_mode:replace,score_mode:sum)和:
我可以使用field_value_factor将createdDate添加到乐谱中。但是,如果region = DE和language = de,我无法找到一个function_score function来为分数添加300000000000000。
是否可以在不使用script_score的情况下执行此操作?
答案 0 :(得分:0)
以下是如何操作:
{
"sort": [
{"_score": "desc"},
{"created_date": "desc"}
],
"query": {
"function_score": {
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"constant_score": {
"filter": {
"bool": {
"must": [
{ "term": { "region": "DE" } },
{ "term": { "language": "de" } }
]
}
},
"boost": 3
}
},
{
"constant_score": {
"filter": {
"bool": {
"must": [
{ "term": { "region": "DE" } },
{ "not": { "term": { "language": "de" } } }
]
}
},
"boost": 2
}
},
{
"constant_score": {
"filter": {
"bool": {
"must": [
{ "not": { "term": { "region": "DE" } } },
{ "term": { "language": "en" } }
]
}
},
"boost": 1
}
}
]
}
}
}
}
}