Neo4j密码计算并显示两个给定节点之间的所有关系 [英] Neo4j cypher to count and display all the relationship between two given nodes

查看:357
本文介绍了Neo4j密码计算并显示两个给定节点之间的所有关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我正在使用neo4j rest api, 在第一步中,我想收集信息,例如两个给定节点之间存在多少关系.

Here I am using neo4j rest api, in first step I want to collect information like how many relationships are there between two given nodes.

示例:MATCH (n:Node {id: {parameter1}})-[r:someType]-(m:Node {id: {parameter2}}) RETURN COUNT(r)

然后,我想收集所有分配给边缘的值,以便我可以进行进一步的计算.我需要两个给定节点之间的所有不同类型的关系及其属性.

Then I would like to collect all the values assigned to the edges so I can calculate further calculations. I need all the different types of relationships and their properties between two given nodes.

如果可能的话,我想使用单密码.

If it is possible I would like to do it in single cypher.

推荐答案

然后我要收集分配给边缘的所有值

Then I would like to collect all the values assigned to the edges

MATCH (n:Node {id: {parameter1}})-[r:someType]-(m:Node {id: {parameter2}})
RETURN COUNT(r) AS count, COLLECT(r) AS rels 

请注意,我唯一更改的是在返回值中添加了collect(r) AS rels,这为您提供了Relationship对象的集合,这些对象表示这些节点之间带有标签someType的所有边.

Note that the only thing I changed was adding collect(r) AS rels to the return, which gives you a collection of Relationship objects representing all edges with label someType between these nodes.

要获取任何类型的所有边缘:

To get all edges of any type:

MATCH (n:Node {id: {parameter1}})-[r]-(m:Node {id: {parameter2}})
RETURN COUNT(r) AS count, collect(r) AS rels ORDER BY labels(r)

MATCH中删除标签要求,以返回任何类型的所有关系的集合.按标签对集合进行排序,以便按类型对返回的关系列表进行排序,从而使您可以轻松地根据需要对它们进行区分,以进行进一步的计算"

Remove the label requirement from the MATCH to return a collection of all relationships of any type. Order that collection by label, so that the list of relationships returned is sorted by type, making it easy for you to distinguish between them as needed for the purposes of your "further calculations"

此代码未经测试,我不确定100%确定您可以调用集合中的标签.如果没有,请告诉我,我将提供替代解决方案.

这篇关于Neo4j密码计算并显示两个给定节点之间的所有关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆