我正在尝试使用DSL语法构建以下查询:
GET /_search
{
"query": {
"function_score": {
"filter": {
"term": { "city": "Barcelona" }
},
"functions": [
{
"filter": { "term": { "features": "wifi" }},
"weight": 1
},
{
"filter": { "term": { "features": "garden" }},
"weight": 1
},
{
"filter": { "term": { "features": "pool" }},
"weight": 2
}
],
"score_mode": "sum",
}
}
}
但是,使用NEST客户端时,在function_score中似乎没有
filter
选项。我可以确认查询是 flex 的。
最佳答案
我不确定要定位的是哪个版本的Elasticsearch,但是自Elasticsearch 2.0 when queries and filters were merged以来,filter
查询上没有function_score
属性。 NEST公开了Elasticsearch API中可用的功能,因此该属性在NEST 1.x中可用,但在任何更高版本中均不可用。
Filters on individual functions exist
var response = client.Search<object>(s => s
.Query(q => q
.FunctionScore(fs => fs
.Functions(fu => fu
.Weight(w => w
.Weight(1)
.Filter(wf => wf
.Term("features", "pool")
)
)
)
)
)
);
关于elasticsearch - Nest筛选功能分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45636690/