[英]ArangoDB aggregation counts of objects in array
I'm trying to generate facets (aggregation counts) for the following documents in a graph (based on collections rather than a named graph): 我正在尝试为图中的以下文档生成构面(聚合计数)(基于集合而不是命名图):
{
"relation": "decreases",
"edge_type": "primary",
"subject_lbl": "act(p(HGNC:AKT1), ma(DEFAULT:kin))",
"object_lbl": "act(p(HGNC:CDKN1B), ma(DEFAULT:act))",
"annotations": [
{
"type": "Disease",
"label": "cancer",
"id": "cancer"
},
{
"type": "Anatomy",
"label": "liver",
"id": "liver"
}
]
}
The following works great to get facets (aggregation counts) for the edge_type: 以下工作非常有用,可以获取edge_type的构面(聚合计数):
FOR doc in edges
COLLECT
edge_type = doc.edge_type WITH COUNT INTO edge_type_cnt
RETURN {edge_type, edge_type_cnt}
I tried the following to get counts for the annotations[*].type value: 我尝试了以下操作以获取注解[*]。type值的计数:
FOR doc in edges
COLLECT
edge_type = doc.edge_type WITH COUNT INTO edge_type_cnt,
annotations = doc.annotations[*].type WITH COUNT INTO anno_cnt
RETURN {edge_type, edge_type_cnt, annotations, anno_cnt}
Which results in an error - any ideas what I'm doing wrong? 这会导致错误-任何想法我在做什么错? Thanks!
谢谢!
Thanks to this thread: https://groups.google.com/forum/#!topic/arangodb/vNFNVrYo9Yo linked to from this Question: ArangoDB Faceted Search Performance pointed me in the right direction. 感谢以下主题提供的链接: https : //groups.google.com/forum/#!topic/arangodb/vNFNVrYo9Yo与此问题相关的链接: ArangoDB多面搜索性能为我指明了正确的方向。
FOR doc in edges
FOR anno in doc.annotations
COLLECT anno_type = anno.type WITH COUNT INTO anno_cnt
RETURN {anno_type, anno_cnt}
Results in: 结果是:
Anatomy 4275
Cell 2183
CellLine 2093
CellStructure 2081
Disease 2126
Organism 2075
TextLocation 2121
Looping over the edges and then the annotations array is the key that I was missing. 遍历边缘,然后注释数组是我丢失的关键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.