0
votes

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
1
Are you sure the name of the relationship is written correctly? Case matters.Werner Kvalem Vesterås
Yes I'm sure. I made another example which I practically use .. I'm trying to query over one relationship type over several steps. The first and second step is correct, but the third step show a incorrect value for me. There are two nodes which are present in the second step, but missing in the third step! how could this happen?DoEasy
Can you share the output of these two queries by including the node ids of artist,x,y and sim?Luanne
Yes of course, I include them in the example ..DoEasy
Freaky...can't seem to spot what it is either. Possible to share your db somehow?Luanne

1 Answers

0
votes

i see no problem in there:

artist-[:SimilarTo]->x-[:SimilarTo]->sim

gives you identifiers artist and sim where in some cases the artist=sim. whereas

artist-[:SimilarTo]->x-[:SimilarTo]->y-[:SimilarTo]->sim

gives you identifiers artist, x, y, sim where the y<>artist because it is folowed by sim -> 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]->sim

will give you imo 210292 209410 210292 209410 xxxxx

i 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:

MATCH artist-[:SimilarTo]->x-[:SimilarTo]->sim
WHERE artist.artistName! = 'Shining Fury' 
AND Id(artist)<>Id(sim)

in case you must go through the loops, then do the dividing into 2 parts query solution