Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 利用NEST for ES FunctionScore和可变数量的函数_C#_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Nest - Fatal编程技术网 elasticsearch,nest,C#,elasticsearch,Nest" /> elasticsearch,nest,C#,elasticsearch,Nest" />

C# 利用NEST for ES FunctionScore和可变数量的函数

C# 利用NEST for ES FunctionScore和可变数量的函数,c#,elasticsearch,nest,C#,elasticsearch,Nest,利用NEST的0.12版本,我需要通过function score API构建内置支持,以便在我的c#应用程序中拥有数量可变的函数参数,如下所述。基于API的当前形状,我无法找到有条件地添加函数或将函数项的原始数组传递给查询描述符对象的方法。在0.12中是否有不同的方法来实现这一点 bool useFunctionScoreForCreatedDate = true; bool useFunctionScoreForAge = true; var s = new SearchDescripto

利用NEST的0.12版本,我需要通过function score API构建内置支持,以便在我的c#应用程序中拥有数量可变的函数参数,如下所述。基于API的当前形状,我无法找到有条件地添加函数或将函数项的原始数组传递给查询描述符对象的方法。在0.12中是否有不同的方法来实现这一点

bool useFunctionScoreForCreatedDate = true;
bool useFunctionScoreForAge = true;

var s = new SearchDescriptor<ExampleDataObject>().From(0).Size(10)
  .Query(aa => aa
   .FunctionScore(fs => fs
       .Query(qq => qq.MatchAll())
       .Functions(
        // need to conditionally add this function score to the FunctionScoreFunction[] if useFunctionScoreForCreatedDate
        f => f.Linear(x => x.createddate, d => d.Scale("0d")),
       // need to conditionally add this function score to the FunctionScoreFunction[] if useFunctionScoreForAge
        f => f.Exp(x => x.age, d => d.Scale("0.5")),
        f => f.BoostFactor(2)
       )
      .ScoreMode(FunctionScoreMode.sum)
     )
).Fields(x => x.title);
bool useFunctionScoreForCreatedDate=true;
bool usefunctionscorefow=true;
var s=new SearchDescriptor().From(0).Size(10)
.Query(aa=>aa
.FunctionScore(fs=>fs
.Query(qq=>qq.MatchAll())
.功能(
//如果使用FunctionScoreForCreatedDate,则需要有条件地将此函数分数添加到FunctionScoreFunction[]
f=>f.Linear(x=>x.createddate,d=>d.Scale(“0d”)),
//如果使用FunctionScore,则需要有条件地将此函数分数添加到FunctionScore函数[]
f=>f.Exp(x=>x.age,d=>d.Scale(“0.5”)),
f=>f.BoostFactor(2)
)
.ScoreMode(FunctionScoreMode.sum)
)
).字段(x=>x.title);

看起来像
.Functions()
方法和
.FunctionScore()
接受
functionscoresfunctionsdesdescriptor
对象。因此,您应该能够使用类似于以下内容的内容

 bool useFunctionScoreForCreatedDate = true;
 bool useFunctionScoreForAge = true;

 var fsFunctionsDescriptor = new FunctionScoreFunctionsDescriptor<ExampleDataObject();
 if (useFunctionsScoreForCreatedDate)
 {
      fsFunctionsDescriptor.Linear(x => x.createdate, d => d.Scale("0d"));
 }

 if (useFunctionScoreForAge) 
 {
      fsFunctionsDescriptor.Exp( x => x.age, d => d.Scale("0.5"));
 }
 fsFunctionsDescriptor.BoostFactor(2);

 var s = new SearchDescriptor<ExampleDataObject>().From(0).Size(10)
   .Query(aa => aa
   .FunctionScore(fs => fs
       .Query(qq => qq.MatchAll())
       .Functions(fsFunctionsDescriptor)
       .ScoreMode(FunctionScoreMode.sum)
     )
 ).Fields(x => x.title);
bool useFunctionScoreForCreatedDate=true;
bool usefunctionscorefow=true;
var fsFunctionsDescriptor=新函数ScoreFunctionsDescriptor x.createdate,d=>d.Scale(“0d”);
}
如果(使用函数)
{
Exp(x=>x.age,d=>d.Scale(“0.5”);
}
fsFunctionsDescriptor.BoostFactor(2);
var s=new SearchDescriptor().From(0).Size(10)
.Query(aa=>aa
.FunctionScore(fs=>fs
.Query(qq=>qq.MatchAll())
.函数(fsFunctionsDescriptor)
.ScoreMode(FunctionScoreMode.sum)
)
).字段(x=>x.title);

这是我最初尝试的方法,无法使其与可用的单一重载一起工作。这是收到的错误消息:无法将类型“Nest.FunctionScoreFunctionsDescriptor”隐式转换为“Nest.FunctionScoreFunction”。我唯一可用的方法是函数描述符参数后跟函数[],我无法动态添加该函数。