我想要一个函数,它获取所有结果,并且仅在它们与过滤器匹配时才对它们进行排序。我已经尝试过这些查询,但没有结果。有人可以帮忙吗?
试用1:
{
"query": {
"function_score": {
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"term": {
"category_boats": "motor_boat"
}
}
]
}
}
}
},
"functions": [
],
"score_mode": "first"
}
}
}
Run Code Online (Sandbox Code Playgroud)
试用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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
在最后一个代码中,我收到错误:没有注册名为 [weight] 的函数。] 那么过滤器的权重是否受支持?一些帮助?
在elasticsearch 1.4中添加了对权重的支持,之前它被称为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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6072 次 |
最近记录: |