我希望有一个功能,它可以获取所有结果,只有在匹配过滤器时才会对它们进行排序。 我试过这些查询但没有结果。有人可以帮忙吗?
试用1:
{
"query": {
"function_score": {
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"term": {
"category_boats": "motor_boat"
}
}
]
}
}
}
},
"functions": [
],
"score_mode": "first"
}
}
}
试用2:
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"functions": [
{
"filter": {
"term": {
"boat_type": "offshore_yacht"
}
},
"weight": 1
},
{
"filter": {
"term": {
"year_built": "2016"
}
},
"weight": 1
},
{
"filter": {
"term": {
"manufacturer": "MasterCraft"
}
},
"weight": 2
}
],
"score_mode": "first"
}
}
}
在最后一段代码中我收到错误:没有注册名称为[weight]的函数。 过滤器是否支持重量?一些帮助?
答案 0 :(得分:1)
在弹性搜索1.4中添加了对weight的支持,之前它被称为boost_factor
示例:
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"functions": [
{
"filter": {
"term": {
"boat_type": "offshore_yacht"
}
},
"boost_factor": 1
},
{
"filter": {
"term": {
"year_built": "2016"
}
},
"boost_factor": 1
},
{
"filter": {
"term": {
"manufacturer": "MasterCraft"
}
},
"boost_factor": 2
}
],
"score_mode": "first"
}
}
}