gpt4 book ai didi

c# - 如何使用 .NET NEST 客户端在函数评分查询中创建过滤器

转载 作者:行者123 更新时间:2023-12-02 22:56:14 25 4
gpt4 key购买 nike

In Elasticsearch Document描述功能分数查询显示代码如下

GET /_search
{
"query": {
"function_score": {
"query": { "match_all": {} },
"boost": "5",
"functions": [
{
"filter": { "match": { "test": "bar" } },
"random_score": {},
"weight": 23
},
{
"filter": { "match": { "test": "cat" } },
"weight": 42
}
],
"max_boost": 42,
"score_mode": "max",
"boost_mode": "multiply",
"min_score" : 42
}
}
}

我将此查询写到 object initializer syntax
var searchRequest = new SearchRequest<ProductType>
{
Query = new FunctionScoreQuery()
{
Query = new MatchAllQuery {},
Boost = 5,
Functions = new List<IScoreFunction>
{
Filters...?
},
MaxBoost = 42,
ScoreMode = FunctionScoreMode.Max,
BoostMode = FunctionBoostMode.Max,
MinScore = 42
}
};

如何在函数中构建过滤器?
IScoreFunction接口(interface)只允许 ExponentialDecayFunction , GaussDateDecayFunction , LinearGeoDecayFunction , FieldValueFactorFunction , RandomScoreFunction , WeightFunction , ScriptScoreFunction

最佳答案

函数是 IScoreFunction 的集合.在示例 JSON 中,第一个函数是随机得分函数,第二个函数是权重函数。链接的 Query DSL 示例有不同功能的示例,这里有一个匹配上面 JSON 的示例

var client = new ElasticClient();

var searchRequest = new SearchRequest<ProductType>
{
Query = new FunctionScoreQuery()
{
Query = new MatchAllQuery { },
Boost = 5,
Functions = new List<IScoreFunction>
{
new RandomScoreFunction
{
Filter = new MatchQuery
{
Field = "test",
Query = "bar"
},
Weight = 23
},
new WeightFunction
{
Filter = new MatchQuery
{
Field = "test",
Query = "cat"
},
Weight = 42
}
},
MaxBoost = 42,
ScoreMode = FunctionScoreMode.Max,
BoostMode = FunctionBoostMode.Multiply,
MinScore = 42
}
};

var searchResponse = client.Search<ProductType>(searchRequest);

关于c# - 如何使用 .NET NEST 客户端在函数评分查询中创建过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53609236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com