Query all the paths to one node with one kind of relationship neo4j

In a graph, there are multiple relationships between nodes with the same label to connect them together.
What I want to do is to find all the paths to a specific node(e.g. node A), and only through a specific type of relationships.

The graph is shown below: I only want to keep DEPEND_ON relationships between Artifacts, without NEXT relationships.

MATCH p = (connected)-[:DEPEND_ON*]->(root:Artifact {gav: "com.twitter:finagle-core_2.11:6.25.0"})
  WHERE root <> connected
RETURN distinct connected,root,relationships(p)

Hello @jayxu688 :slight_smile:

On Neo4j Desktop, when you access the parameters of the interface:

You should be able to uncheck the box, do it and restart your query :slight_smile:


Hi, Cobra.
Thanks for the quick reply.
But we have a little bit of misunderstanding here.

I mean I want to use cypher query to get the result set, not using Neo4j desktop to hide the relationships in the result set.

What I want to do here is using "DEPEND_ON" relationships to get all the paths(nodes connected using “DEPEND_ON” relationships) to the node with certain "gav" property value. In other word, using cypher query to exclude the "NEXT" relationships from the resulted subgraph, only keeping all the nodes directly or indirectly "DEPEND_ON" the Artifact node with "com.twitter:finagle-core_2.11:6.25.0" value.

If you can give me some methods to optimizing Cypher to speed up the query, it would be more excellent.

The problem is that's coming from Neo4j Desktop and not from Cypher, I don't know why they develop that feature. But don't worry, it's only when you display the graph, if you just want to display data, it won't appear :slight_smile:

Your Cypher query looks optimized :wink:

Wow. Thanks for your knowhow.
I was struggling on this for days.
I Think I only returned the "DEPEND_ON" relationships and the nodes on the path, but the result makes me wonder I was doing wrong.

A further question:
when I wanted to do the query for the node with GAV property value of "org.slf4j:slf4j-api:1.6.1", which is a node directly or indirectly depended on by tons of projects in this Maven Central Repository graph. The result set may be over 1 million or something. Can neo4j handle this, OR, shall I add depth like [DEPEND_ON*1..3] after the relationship.


Neo4j will limit the nodes displayed on the screen, by default it's 300 I guess.
[DEPEND_ON*1..3] will limit the number of hop for each node (3 hop in your case), if you want to limit the number of results you can also use LIMIT :slight_smile:

1 Like

I want to get the whole graph and hops.
But the performance of my cypher I wrote above to get a big subgraph like this is nearly 0 . I was not able to get the result.
And are there any ways for me to get this kind of big result set in a proper way.

Sorry for my English, it’s not my first language. I know it may make the communication inefficient. :grimacing:

You will need a good computer if you want to be able to display the whole graph, Neo4j Desktop has not been done for this, you should have a look at Neo4j Bloom :slight_smile:

1 Like

Thank you very much for your patient answering, I will go to check it out immediately.

1 Like