使用密码查询获取neo4j中的连接图 [英] Get connected graphs in neo4j by using cypher query

查看:103
本文介绍了使用密码查询获取neo4j中的连接图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何修改密码查询,以使其能够给出所有连接的图(表示直接或间接相互连接的节点和关系的集合)作为查询的结果。

How can we modify the cypher query so that it can give all the connected graphs (means the set of nodes and relationships that are connected to each other directly or indirectly) as a result for the query.

我可以使用遍历框架满足我的要求吗?

Can I use traversal framework for my requirement?

用例是:
我需要从neo4j获取所有连接的图,并将它们的信息作为集群存储在其他数据库中。一组连接的图= 1个集群
我需要分离连接的图,然后将节点/关系的某些属性的合计存储并存储在其他数据库中。

The use case is: I need to get all the connected graphs from neo4j and store their information as an "cluster" in other database.1 group of connected graph = 1 cluster. I need to separate the connected graphs and then store the aggregate of some of the properties of nodes/relations and store it in other db.

我正在使用REST与neo4j db进行交互。

I am using REST to interact with neo4j db.

推荐答案

虽然不会很快。

使用Java专用的算法可以更快地收集数据。

A dedicated algorithm in Java will be much faster collecting that data.


  1. 获取每个节点的所有节点


  2. 如果它已连接到已连接节点的任何第一个节点图(shortestPath)跳过它,所有路径的所有末端节点的集合
    else

MATCH (n) 
WITH COLLECT(n) as nodes
RETURN REDUCE(graphs = [], n in nodes | 
  case when 
    ANY (g in graphs WHERE shortestPath((n)-[*]-(head(g))) 
         then graphs 
         else graphs + [[p in (n)-[*0..]-() | nodes(p)[length(p)-1]]]
         end ))

这篇关于使用密码查询获取neo4j中的连接图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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