Alexandros Ladas
Alexandros Ladas

Reputation: 23

Return a single relationship from multiple relationships between 2 nodes in neo4j

I am new to Neo4j and I have some trouble filtering out relationships in a return statement. I created two nodes and 3 instances of the same relationship between these two nodes that differ only in the value of the properties:

create (p:person {name:'batman'})
create (p:person {name:'superman'})

match (p1:person {name:'batman'}),(p2:person{name:'superman'}) create (p1)-  [h:HATES {intensity: 1}]->(p2)
match (p1:person {name:'batman'}),(p2:person{name:'superman'}) create (p1)-  [h:HATES {intensity: 2}]->(p2)
match (p1:person {name:'batman'}),(p2:person{name:'superman'}) create (p1)-  [h:HATES {intensity: 3}]->(p2)

When I try to visualise only one of those relationships (eg: intensity=2) with this code:

match (a: person)-[h:HATES]->(b: person) where h.intensity=2  return  a,h,b

all 3 relationships are plotted:

all relationships

Whereas by looking at the data only the filtered relationship is returned "a" "h" "b"

{"name":"batman"}   {"intensity":2} {"name":"superman"}

Does anyone know how to plot only the corresponding relationship?

Upvotes: 2

Views: 364

Answers (1)

Bruno Peres
Bruno Peres

Reputation: 16365

This is the default behavior of the Neo4j browser. If you are using Neo4j 3.2 go to "Browser settings" and uncheck the option "Connect result nodes".

Browser settings

After it the result showld be:

Result

If you are using a older version of Neo4j you should toggle the option highlighted in the image below:

Older versions

Upvotes: 5

Related Questions