cancel
Showing results for 
Search instead for 
Did you mean: 

Combine relationships and pass parameters

iamtheef
Node Link

How can I query multiple relationships and pass filter for just one of them?

eg:

match (u:User)-[:PURCHASED|r:RATED {r.value > 3.5}]->(i:Item) return i
I wanna query all the items a user has interacted and only include those which the user rated above a limit.
1 ACCEPTED SOLUTION

Got it..try this:

match (u:User)-[r]->(i:Item)
where r:PURCHASED or (r:RATED and r.value > 3.5)
return u, i

View solution in original post

5 REPLIES 5

glilienfield
Ninja
Ninja

Do you mean you would like to get all the items a user purchased where the user also rated with a rating greater than 3.5? If so, try this.

match (u:User)-[:PURCHASED]->(i:Item)

where exists {
match (u)-[r:RATED]->(i)

where r.value > 3.5

}

return u.name, collect(i.name)

No. I mean I wanna get all the items a user either purchased OR rated > some value.

iamtheef
Node Link
match (u:User)-[r:PURCHASED|RATED]->(i:Item) where r.value>3.4 return u, i

This kinda works but the other of the edges doesn't hold values. Only RATED edge has a value.

Nope, it only returns RATED nodes by the user.

Got it..try this:

match (u:User)-[r]->(i:Item)
where r:PURCHASED or (r:RATED and r.value > 3.5)
return u, i

Worked. Thank you!

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.