I’m trying to query nodes via Cypher with a specific relationship type.
So there are two nodes A (ID 1) and B (ID 2).
I’m using the Cypher Console within the Administration GUI.
If I do this:
rel:1
I get a result of two relationships (IDs 10 and 11) two the same node (ID 3) (I know that is bad but that’s the data).
If I look into the relationships there is shown:
Node 1 SimilarTo Node 3
Node 1 SimilarTo Node 3
If I try this:
START n=node(*) MATCH n-[:SimilarTo]->b WHERE n.Name='A'
I get an empty result!?
So my question is, why do I get that empty result, although there exist two relationships which have the right start node and the right end nodes?
I do not understand it.
If you have any suggestions please let me know 😉
OK I make another example..
I do following query:
START artist=node:artists('artistMbid:*')
MATCH artist-[:SimilarTo]->x-[:SimilarTo]->sim
WHERE artist.artistName! = 'Shining Fury'
RETURN artist.artistName, x.artistName, sim.artistName
And get this result (is correct):
artist.artistName x.artistName sim.artistName
"Shining Fury" "Dragonsfire" "Holy Cross"
"Shining Fury" "Dragonsfire" "Holy Cross"
"Shining Fury" "Dragonsfire" "Lorenguard"
"Shining Fury" "Dragonsfire" "Lorenguard"
"Shining Fury" "Dragonsfire" "Shining Fury"
"Shining Fury" "Dragonsfire" "Shining Fury"
If I do that:
START artist=node:artists('artistMbid:*')
MATCH artist-[:SimilarTo]->x-[:SimilarTo]->y-[:SimilarTo]->sim
WHERE artist.artistName! = 'Shining Fury'
RETURN artist.artistName, x.artistName, y.artistName, sim.artistName
I get this (incorrect):
artist.artistName x.artistName y.artistName sim.artistName
"Shining Fury" "Dragonsfire" "Holy Cross" "Dragonsfire"
"Shining Fury" "Dragonsfire" "Holy Cross" "Ruffians"
"Shining Fury" "Dragonsfire" "Holy Cross" "Dragonsfire"
"Shining Fury" "Dragonsfire" "Holy Cross" "Ruffians"
"Shining Fury" "Dragonsfire" "Lorenguard" "Holy Cross"
"Shining Fury" "Dragonsfire" "Lorenguard" "Nightqueen"
"Shining Fury" "Dragonsfire" "Lorenguard" "Dragonsfire"
"Shining Fury" "Dragonsfire" "Lorenguard" "Holy Cross"
"Shining Fury" "Dragonsfire" "Lorenguard" "Nightqueen"
"Shining Fury" "Dragonsfire" "Lorenguard" "Dragonsfire"
It is incorrect because I’m missing The artist “Shining Fury” under y.artistName, like I got it in the step before.
I can’t find my mistake!
Another edit..
Query 1
START artist=node:artists('artistMbid:*')
MATCH artist-[:SimilarTo]->x-[:SimilarTo]->sim
WHERE artist.artistName! = 'Shining Fury'
RETURN ID(artist), ID(x), ID(sim)
result:
ID(artist) ID(x) ID(sim)
210292 209410 228580
210292 209410 228580
210292 209410 212568
210292 209410 212568
210292 209410 210292
210292 209410 210292
Query2:
START artist=node:artists('artistMbid:*')
MATCH artist-[:SimilarTo]->x-[:SimilarTo]->y-[:SimilarTo]->sim
WHERE artist.artistName! = 'Shining Fury'
RETURN ID(artist), ID(x), ID(y), ID(sim)
result:
ID(artist) ID(x) ID(y) ID(sim)
210292 209410 228580 209410
210292 209410 228580 202357
210292 209410 228580 209410
210292 209410 228580 202357
210292 209410 212568 228580
210292 209410 212568 202279
210292 209410 212568 209410
210292 209410 212568 228580
210292 209410 212568 202279
210292 209410 212568 209410
i see no problem in there:
artist-[:SimilarTo]->x-[:SimilarTo]->simgives you identifiers
artistandsimwhere in some cases the artist=sim. whereasartist-[:SimilarTo]->x-[:SimilarTo]->y-[:SimilarTo]->simgives you identifiers
artist, x, y, simwhere they<>artistbecause it is folowed bysim-> i mean, if you will be given the same identifier as in the first case, than the cypher match would run into an infinite loop, i.e.210292 209410 210292 209410(i bet the “Shining Fury” has connection only to “DragonsFly” and thus there simply can’t be another sim identifier other than again the “DragonsFly”.try to add 1 more identifier and you will also see the part of the first query, e.g.:
artist-[:SimilarTo]->x-[:SimilarTo]->y-[:SimilarTo]->z-[:SimilarTo]->simwill give you imo
210292 209410 210292 209410 xxxxxi suggest to be 100% sure you get the same nodes under the identifiers, either divide the query into 2 separate parts (as suggested in the comments with WITH) or strictly define you don’t want any cycle in the query:
in case you must go through the loops, then do the dividing into 2 parts query solution