Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find 2nd level of connections in neo4j?

Tags:

neo4j

My neo4j graph shows like below..
300 is connected to 100 and 100 is connected to 201 and 400.
I want to find out the 2nd level of connectivity in neo4j. For example: the 2nd level of node for 300 should return me 201 and 400
Is it possible in neo4j?

enter image description here

enter image description here

when I use below cypher query:

MATCH (n)-[:CALLED*2]-(result) WHERE n.name = '300' RETURN result
It should give me only 201 and 400 ,but it return like below

enter image description here

like image 363
Amaresh Avatar asked Apr 21 '15 06:04

Amaresh


People also ask

How many relationships can Neo4j handle?

The standard store format of neo4j allows for 65k different relationship types.

How are relationships stored in Neo4j?

Properties are stored as a linked list of property records, each holding a key and value and pointing to the next property. Each node and relationship references its first property record. The Nodes also reference the first relationship in its relationship chain. Each Relationship references its start and end node.

How do I return all nodes and relationships in Neo4j?

Return all elements When you want to return all nodes, relationships and paths found in a query, you can use the * symbol.


1 Answers

This is very easy in Neo4j. If you're using Cypher it might be something like:

MATCH (n)-[:CALLED]-()-[:CALLED]-(result)
WHERE n.id = 300
RETURN result

I'm assuming here that the id property is what is holding the identifying numbers, but obviously you can change that.

You can even do variable length paths like this:

MATCH (n)-[:CALLED*2]-(result)
WHERE n.id = 300
RETURN result

Part of the problem here, though, is that this will return node #200. One query that would fit the result your looking for is:

MATCH (n)-[:CALLED]->()<-[:CALLED]-(result)
WHERE n.id = 300
RETURN result

This matches only where the middle node has the relationships pointing to it.

like image 193
Brian Underwood Avatar answered Oct 11 '22 20:10

Brian Underwood