Neo4j (cypher): How do I find all nodes with a specific relationship?

2k Views Asked by At

In a neo4j database with nodes, linked by the 'ARTICLE_OF' relationship, how do I find all nodes with this relationship? Direction doesn't matter.

I tried a possible solution from here, but it seems outdated. I swapped SOME_RELATIONSHIP with my ARTICLE_OF, but it didn't work.

start n=node(*)
match n-[:ARTICLE_OF]-()
return distinct n

When I run it I get the following error:

START is deprecated, use: `MATCH (n)` instead.
        (line 1, column 1 (offset: 0))
"start n=node(*)"
 ^

I tried swapping start with match, but that only resulted in more errors. Let me know if you want to see those as well, but I think someone with experience might immediately see what I'm doing wrong.

2

There are 2 best solutions below

0
On BEST ANSWER

Since your question uses the neo4j-browser tag, I assume you are using the Neo4j Browser.

The Neo4j Browser has a quick way to display (up to 25) instances of a relationship type. In the Browser's left-hand sidebar, you'll see a Relationship Types section. If you click on one of the relationship types in that section, the Browser will execute a query to get the relationships of that type (limited to 25). You can adjust the query (e.g., by increasing or removing the LIMIT) as you wish.

Here is an example of a generated query:

MATCH p=()-[r:ARTICLE_OF]->() RETURN p LIMIT 25

NOTE: The r variable can be omitted, as it is never used.

0
On

I think I found an answer, but please provide a better solution if you find flaws

MATCH (n)-[r:ARTICLE_OF]->(k) RETURN n, r, k

Did the trick, I think