I have this simple graph:
create (a:ent {id:'a'})-[:rel]->(:ent {id:'b'})-[:rel]->(c:ent {id:'c'})-[:rel]->(d:ent {id:'d'})-[:rel]->(:ent {id:'e'})-[:rel]->(a),
(d)-[:rel]->(c),
(c)-[:rel]->(f:ent {id:'f'})-[:rel]->(g:ent {id:'g'})-[:rel]->(a),
(g)-[:rel]->(f)
Given is 'a', that is node (:ent {id:'a'})
, I want to write query that returns "exactly two unique longest" paths:
a->b->c->d->e
a->b->c->f->g
As you can see here I should be considering cycles in the graph here. It seems that query suggested here should be fine, which I rewrote as follows:
MATCH path=(:ent{id:'a'})-[:rel*]->(:ent)
WHERE ALL(n in nodes(path)
WHERE 1=size(filter(m in nodes(path)WHERE m.id=n.id))
)
RETURN path
I know the query does not give exact result as I intend to get, however if I understand the logic correctly, it does at least avoid the cyclic paths. I felt this query can be a good starting point. But it is giving me weird error:
key not found: UNNAMED26
Whats wrong here? I am unable to pinpoint the error in the cypher with this unclear error description.
Update
I tried a new simpler query:
MATCH path=(s:ent{id:'a'})-[:rel*]->(d:ent)
WHERE not (d)-[:rel]->() OR (d)-[:rel]->(s)
RETURN extract(x IN nodes(path)| x.id) as result
It returns:
╒═════════════════════╕
│result │
╞═════════════════════╡
│[a, b, c, d, e] │
├─────────────────────┤
│[a, b, c, d, c, f, g]│
├─────────────────────┤
│[a, b, c, f, g] │
└─────────────────────┘
As you can see it has one redundant path [a, b, c, d, c, f, g]
caused due to the cycle (d)<->(c)
cycle. I honestly feel the original/first query in this post should eliminate it. Can someone please tell me how can I make it work...?