带有脚本的 Elastic NEST SumAggregation
Elastic NEST SumAggregation with Script
我有这个弹性查询:
"aggs":{
"GroupByDomeinRelatieCode":{
"aggs":{
"SumNettoRegelBedrag":{
"sum":{
"script": {
"lang": "painless",
"source": "doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100 "
}
}
}
},
"terms":{
"field":"domeinRelatieCode.keyword",
"size":10000
}
},
"TotalSumAggragation":{
"sum":{
"script": {
"lang": "painless",
"source": "doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100 "
}
}
}
}
我需要使用对象初始化程序将其转换为 C# Nest。
我当前的代码:
var aggs = new AggregationDictionary()
{
{ "GroupByDomeinRelatieCode" , new TermsAggregation("GroupByDomeinRelatieCode")
{
Field = Infer.Field<ElasticInvoiceLine>(x => x.DomeinRelatieCode.Suffix("keyword")),
Size = 10000,
Aggregations = new SumAggregation("SumNettoRegelBedrag", ADD SCRIPT HERE?)
}
},
{ "TotalSumAggragation", new SumAggregation("TotalSumAggragation", ADD SCRIPT HERE?)}
};
我尝试使用 ScriptQuery 和 ScriptField,但 SumAggregation 不接受。
var script = new ScriptQuery
{
Name = "UitgesteldeKorting",
Script = new InlineScript("doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100")
{
Lang = "painless"
},
};
var scriptField = new ScriptField()
{
Script = new InlineScript("doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100")
{
Lang = "painless"
}
};
我不知道如何将脚本部分添加到 SumAggregations。我怎样才能做到这一点?
谢谢!
你能试试这个吗?
{
"aggs": {
"GroupByDomeinRelatieCode": {
"aggs": {
"SumNettoRegelBedrag": {
"sum": {
"script": "doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100 "
}
}
},
"terms": {
"field": "domeinRelatieCode.keyword",
"size": 10000
}
},
"TotalSumAggragation": {
"sum": {
"script": "doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100 "
}
}
}
}
您可以通过 Script
属性 传递脚本,像这样
Aggregations = new SumAggregation("SumNettoRegelBedrag", null) { Script = new InlineScript("") }
希望对您有所帮助。
我有这个弹性查询:
"aggs":{
"GroupByDomeinRelatieCode":{
"aggs":{
"SumNettoRegelBedrag":{
"sum":{
"script": {
"lang": "painless",
"source": "doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100 "
}
}
}
},
"terms":{
"field":"domeinRelatieCode.keyword",
"size":10000
}
},
"TotalSumAggragation":{
"sum":{
"script": {
"lang": "painless",
"source": "doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100 "
}
}
}
}
我需要使用对象初始化程序将其转换为 C# Nest。 我当前的代码:
var aggs = new AggregationDictionary()
{
{ "GroupByDomeinRelatieCode" , new TermsAggregation("GroupByDomeinRelatieCode")
{
Field = Infer.Field<ElasticInvoiceLine>(x => x.DomeinRelatieCode.Suffix("keyword")),
Size = 10000,
Aggregations = new SumAggregation("SumNettoRegelBedrag", ADD SCRIPT HERE?)
}
},
{ "TotalSumAggragation", new SumAggregation("TotalSumAggragation", ADD SCRIPT HERE?)}
};
我尝试使用 ScriptQuery 和 ScriptField,但 SumAggregation 不接受。
var script = new ScriptQuery
{
Name = "UitgesteldeKorting",
Script = new InlineScript("doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100")
{
Lang = "painless"
},
};
var scriptField = new ScriptField()
{
Script = new InlineScript("doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100")
{
Lang = "painless"
}
};
我不知道如何将脚本部分添加到 SumAggregations。我怎样才能做到这一点? 谢谢!
你能试试这个吗?
{
"aggs": {
"GroupByDomeinRelatieCode": {
"aggs": {
"SumNettoRegelBedrag": {
"sum": {
"script": "doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100 "
}
}
},
"terms": {
"field": "domeinRelatieCode.keyword",
"size": 10000
}
},
"TotalSumAggragation": {
"sum": {
"script": "doc['nettoRegelbedrag'].value * (100 - doc['uitgesteldeKortingsPercentage'].value) / 100 "
}
}
}
}
您可以通过 Script
属性 传递脚本,像这样
Aggregations = new SumAggregation("SumNettoRegelBedrag", null) { Script = new InlineScript("") }
希望对您有所帮助。