在neo4j中获取所有连接节点的最有效方法 [英] Most efficient way to get all connected nodes in neo4j

查看:213
本文介绍了在neo4j中获取所有连接节点的最有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的答案显示如何通过已知关系类型的路径获取连接到特定节点的所有节点的列表.

The answer to this question shows how to get a list of all nodes connected to a particular node via a path of known relationship types.

作为对该问题的后续,我试图确定遍历图是否是使所有节点通过 any 路径连接到特定节点的最有效方法.

As a follow up to that question, I'm trying to determine if traversing the graph like this is the most efficient way to get all nodes connected to a particular node via any path.

我的情况:我有一棵群组树(群组可以有任意数量的子代).我使用IS_PARENT_OF关系进行建模.组也可以通过称为角色扮演的特殊关系与任何其他组关联.我使用PLAYS_ROLE_IN关系进行建模.

My scenario: I have a tree of groups (group can have any number of children). This I model with IS_PARENT_OF relationships. Groups can also relate to any other groups via a special relationship called role playing. This I model with PLAYS_ROLE_IN relationships.

我想问的最常见的问题是MATCH(n {name: "xxx") -[*]-> (o) RETURN o.name,但是即使在少数节点(4000个节点-需要5秒钟才能返回答案)上,这似乎也非常慢.请注意,该图可能包含循环(n-IS_PARENT_OF->on<-PLAYS_ROLE_IN-o).

The most common question I want to ask is MATCH(n {name: "xxx") -[*]-> (o) RETURN o.name, but this seems to be extremely slow on even a small number of nodes (4000 nodes - takes 5s to return an answer). Note that the graph may contain cycles (n-IS_PARENT_OF->o, n<-PLAYS_ROLE_IN-o).

是不是通过任何路径都无法建立索引的连通性?

Is connectedness via any path not something that can be indexed?

推荐答案

首先,通过不为起始节点使用标签和索引属性,这首先需要找到图中的所有节点并打开查看该节点是否具有值为"xxx"的属性名称.

As a first point, by not using labels and an indexed property for your starting node, this will already need to first find ALL the nodes in the graph and opening the PropertyContainer to see if the node has the property name with a value "xxx".

第二,如果您现在近似于最大的亲子关系深度,则可能要限制搜索的深度

Secondly, if you now an approximate maximum depth of parentship, you may want to limit the depth of the search

我建议您将选择的标签添加到节点并为name属性建立索引.

I would suggest you add a label of your choice to your nodes and index the name property.

这篇关于在neo4j中获取所有连接节点的最有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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