本文介绍了在elasticsearch和巢之和多领域的乘法的链路聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来elasticsearch。我使用嵌套从elasticsearch查询数据。
I am new to elasticsearch. I use to nest to query data from elasticsearch.
我怎么想办法让聚合后导致多场前pression。
What do i want the way to get result expression of multi fields after aggregations.
例如:
class public InfoComputer
{
int Id {get;set;}
string Name {get;set;}
int price {get;set;}
int quantity {get;set;}
};
var result = client.Search<InfoComputer>(s => s
.Aggregations(a => a
.Terms("names", st => st
.Field(o => o.Name)
.Aggregations(aa => aa
.Sum("price", m => m
.Field(o => o.price)
)
)
)
)
);
这code只能获得总属性的价格。
this code only get Sum attribute price.
我如何获得总和(价格*数量)
与组属性名称?
How can I get Sum (price * quantity)
with group attribute Name?
推荐答案
有在NEST脚本支持,您可以修改您的聚集这样,通过使用脚本()
字段()
:
There is script support in NEST, you can modify your aggregation like this, i.e. by using Script()
instead of Field()
:
var result = client.Search<InfoComputer>(s => s
.Aggregations(a => a
.Terms("names", st => st
.Field(o => o.Name)
.Aggregations(aa => aa
.Sum("price", m => m
.Script("doc['price'].value * doc['quantity'].value")
)
)
)
)
);
这篇关于在elasticsearch和巢之和多领域的乘法的链路聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!