In my db I have some nodes Message
which could have a relationship Replay
, in a form like below:
(:Message)<-[:REPLAY]-(:Message)<-[:REPLAY]-(:Message)...
I want to return a Message which is the start of conversation and all his REPLAY relationships, so I write this query:
MATCH (n)
WHERE
ID(n) = ' + id + '
OPTIONAL MATCH x=(n)<-[:REPLAY*]-(r)
RETURN n AS StartOfConversation, r AS Replay ORDER by r.timestamp ASC
But when the path is too long, the query keeps running.
If i limit the path length with -[:REPLAY*100]-
I get the results
I also get this warning:
Binding relationships to a list in a variable length pattern is deprecated. (Binding a variable length relationship pattern to a variable ('r') 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 r)
How can I improve this query to work on every path ?