我正在尝试根据另一个查询提升查询结果。e、 g.从类别“1”中选择启用的项目,但结果是,我需要首先从品牌“2”中获取项目(得分加倍)。查询示例:
{
"query": {
"bool": {
"must":[
{
"bool": {
"must":[
{
"term":{
"category_path_1":"1"
}
}
]
}
},
{
"bool":{
"should":[
{
"term":{
"status":"enabled"
}
}
]
}
}
],
"should": [
{
"function_score": {
"query": {
"bool": {
"must": [
{
"term": {
"brand": {
"value": "2"
}
}
}
]
}
},
"boost": 2,
"boost_mode": "multiply"
}
}
]
}
}
}
结果(简化):
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 50,
"relation" : "eq"
},
"max_score" : 4.3390245,
"hits" : [
{
"_index" : "product_1",
"_type" : "_doc",
"_id" : "9",
"_score" : 4.3390245,
"_source" : {
"category_path_1" : "1",
"brand" : "2",
"status" : "enabled"
}
},
{
"_index" : "product_1",
"_type" : "_doc",
"_id" : "21",
"_score" : 4.3390245,
"_source" : {
"category_path_1" : "1",
"brand" : "2",
"status" : "enabled"
}
},
{
"_index" : "product_1",
"_type" : "_doc",
"_id" : "3",
"_score" : 2.3390243,
"_source" : {
"category_path_1" : "1",
"brand" : "1",
"status" : "enabled"
}
}
]
}
}
预期结果:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 50,
"relation" : "eq"
},
"max_score" : 7.3390245,
"hits" : [
{
"_index" : "product_1",
"_type" : "_doc",
"_id" : "9",
"_score" : 4.6780486,
"_source" : {
"category_path_1" : "1",
"brand" : "2",
"status" : "enabled"
}
},
{
"_index" : "product_1",
"_type" : "_doc",
"_id" : "21",
"_score" : 4.6780486,
"_source" : {
"category_path_1" : "1",
"brand" : "2",
"status" : "enabled"
}
},
{
"_index" : "product_1",
"_type" : "_doc",
"_id" : "3",
"_score" : 2.3390243,
"_source" : {
"category_path_1" : "1",
"brand" : "1",
"status" : "enabled"
}
}
]
}
}
因此,品牌为“2”的商品 _score
"4.33". 在同一查询中,但没有 function_score
,项有 _score
大约“2.33”。因此 _score
乘以 "boost": 2, "boost_mode": "multiply"
不象我预期的那样工作,它从 boost
而不是乘法。
查询自 function_score
可能更复杂,但结果是,我只需要乘以 _score
所选项目的值。
暂无答案!
目前还没有任何答案,快来回答吧!