RickenbackerMan
RickenbackerMan

Reputation: 41

Neo4j - Jump Nodes

I have a Neo4j graph model that has four (4) nodes. For simplicity, I will name the nodes 1-4.

(n1)--(n2)--(n3)--(n4)

Can I graphically jump from (n1) directly to (n3) without showing (n2)? In my data examples, (n1) can have 1 value, then (n2) can expand into multiple entities and then all (n2) entities will connect to 1 (n3).

My thought was that this would work but it does not

MATCH (n1)--(n2)--(n3) RETURN n1, n3

I get zero results. I want to know if this is possible or if there is another way to graphically show the results. I can probably get results as text but I want it to be shown graphically.

Upvotes: 1

Views: 1081

Answers (2)

cybersam
cybersam

Reputation: 67019

If you mean that you want the neo4j Browser to draw a line connecting n1 and n3 (even though there may not be a relationship between them), yes you can do that.

There are APOC procedures that can generate virtual nodes and relationships -- that is, data structures that look like real nodes and relationships to the neo4j Browser.

For example, if you ran the following in the neo4j Browser, the Browser would display a virtual JUMP relationship between every n1 and n3 pair (assuming that you are only interested in Foo nodes). The virtual relationships do not really exist in the DB.

MATCH (n1:Foo)--()--(n3:Foo)
CALL apoc.create.vRelationship(n1,'JUMP', {}, n3) YIELD rel
RETURN n1, n3, rel;

Upvotes: 1

Rebecca Nelson
Rebecca Nelson

Reputation: 1296

Yes, it is absolutely possible to get skip in-between nodes. Neo4J will of course use them during graph traversal, but it doesn't have to show you the results. There are a few ways of doing this:

With a length-specified pattern match, when you don't really care about what nodes are between. That would look like this:

MATCH (n1:Label1)-[*2]-(n3:Label3) RETURN n1, n3

The variable path in the middle indicates that two relationships are to be traversed to get to node number 3, so there must be one node in between N1 and N2.

The other thing you could do is just don't specify anything about the middle node:

MATCH (n1:Label1)--()--(n3:Label3) RETURN n1, n3

This is similar to the second form of query you posted, except that the second node is not bound to a variable.

Upvotes: 1

Related Questions