如何将每个文档的数量乘以一个值?
问题描述:
假设我有许多文件是这样的:如何将每个文档的数量乘以一个值?
{
"foo": "Something",
"bars":
[
{
"identifier": 1,
"content": "meh",
"quantity": 2
},
{
"identifier": 2,
"content": "bah",
"quantity": 1
}
]
}
我将如何查询10个最本吧[]标识考虑公式时候,它出现*量?
编辑:我取得了这样的事情
{
"size":0,
"aggs":{
"bars":{
"nested":{
"path":"bars"
},
"aggs":{
"top-terms-aggregation":{
"terms":{
"field":"bars.identifier",
"size":10
}
}
}
}
}
}
但仍无法通过数量乘以领域。
答
我实现了这个使用类似这样的查询:
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"bars": {
"nested": {
"path": "bars"
},
"aggs": {
"bars_group": {
"terms": {
"field": "bars.identifier",
"size": 10,
"order": {
"count_bars": "desc"
}
},
"aggs": {
"count_bars": {
"sum": {
"field": "bars.quantity"
}
}
}
}
}
}
}
}
我希望这可以帮助您。
您可能需要一个脚本来执行此操作:https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-fields.html – Adonis