如何在arangob上收集骨料



想象一下,我有一个这样的边缘文档:

[{
"_from": "mobiles/12345",
"_to": "mobiles/54321",
"type": "call",
},
{
"_from": "mobiles/54321",
"_to": "mobiles/32145",
"type": "sms",
},
{
"_from": "mobiles/54321",
"_to": "mobiles/12345",
"type": "call",
}]

当在54321:上查询时,我需要得到这样的列表

{"54321":3,"12345":2,"32145":1}

我试过了,但这不是我想要的:

for v,e,p in any "mobiles/54321" docs
COLLECT from = e._from , to = e._to with count into len 
return {from, to, len}

我在Elasticsearch中用aggs查询很容易做到这一点

您可以"展开";from和_to属性然后根据它们的文档键的联合而不是每个唯一的组合进行分组,计算每个键出现的频率,并为每个bucket返回一个带有动态属性键的对象。外部MERGE((创建了将键映射到计数的最终对象:

RETURN MERGE(
FOR v,e IN ANY "mobiles/54321" docs
FOR id IN [e._from, e._to]
COLLECT key = PARSE_IDENTIFIER(id).key WITH COUNT INTO len
RETURN { [key]: len }
)

最新更新