Filtering by relationship properties

I have graph that looks something like this
MATCH (s {address:"0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac"})<-[:Transfer*]-(t) RETURN s,t

I would like to filter by the relationship property where the value > 0.6 , how do i go about this ?

Bind the relationship to a variable, and then just use WHERE.

MATCH (s {address:"0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac"})<-[rel:Transfer*]-(t) 
WHERE rel.value > 0.6

Note that since you have * on that relationship, this will require that every relationship on the path meet that criteria, not just one.

i tried that earlier but i kept running into the the following error

Type mismatch: expected Any, Map, Node, Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime but was List (line 3, column 7 (offset: 97))
"WHERE rel.value > 0.6"

i managed to resolve this using :

MATCH (s {address:"0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac"})<-[rel:Transfer*]-(t)
WHERE all(a in rel where a.value > 0.6)

However, there is a warning stating

" This feature is deprecated and will be removed in future versions.
Binding relationships to a list in a variable length pattern is deprecated. (Binding a variable length relationship pattern to a variable ('rel') is deprecated and will be unsupported in a future version. The recommended way is to bind the whole path to a variable, then extract the relationships: MATCH p = (...)-[...]-(...) WITH *, relationships(p) AS rel)"

any idea how do i convert the above query to using the newer recommended method instead?

MATCH path=(s {address:"0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac"})<-[:Transfer*]-(t)
WHERE all(a in relationships(path) where a.value > 0.6)

Neo4j Desktop is quite good at giving clues, what syntax to use


Try this:
MATCH p=(s {address:"0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac"})<-[:Transfer]-(t)
WITH *, relationships(p) AS rel
WHERE all (a in rel where a.value < 0.6)

1 Like