Why does this say it creates 1 relationship but it appears there are two?

Hi, I'm quite confused here.. And I'm sure it is me not understanding something, but when I use this query

neo4j@neo4j> MATCH (s:source) where s.url = 'Yahoo News - Latest News & Headlines' CREATE (k:keyword {keyword:'TEST'}), (k) - [:KEYWORD_ADDED_BY] -> (s) RETURN k.keyword as keyword;
+---------+
| keyword |
+---------+
| "TEST" |
+---------+

1 row
ready to start consuming query after 0 ms, results consumed after another 1 ms
Added 1 nodes, Created 1 relationships, Set 1 properties, Added 1 labels

Everything seems to be as I would expect..

however, if I do this query,
neo4j@neo4j> match (a) - [r:KEYWORD_ADDED_BY] - (b) return a,r,b;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| a | r | b |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| (:keyword {keyword: "TEST"}) | [:KEYWORD_ADDED_BY] | (:source {name: "Yahoo News - Latest News & Headlines", url: "Yahoo News - Latest News & Headlines", organizaion: "Copyright (c) 2022 Yahoo! Inc. All rights reserved"}) |
| (:source {name: "Yahoo News - Latest News & Headlines", url: "Yahoo News - Latest News & Headlines", organizaion: "Copyright (c) 2022 Yahoo! Inc. All rights reserved"}) | [:KEYWORD_ADDED_BY] | (:keyword {keyword: "TEST"}) |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

2 rows
ready to start consuming query after 1 ms, results consumed after another 0 ms

It seems to have the relationship in both directions, which is wrong..

And I can do a query with the direction arrows, and they will both show up
neo4j@neo4j> match (a) - [r:KEYWORD_ADDED_BY] -> (b) return a,r,b;
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| a | r | b |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| (:keyword {keyword: "TEST"}) | [:KEYWORD_ADDED_BY] | (:source {name: "Yahoo News - Latest News & Headlines", url: "Yahoo News - Latest News & Headlines", organizaion: "Copyright (c) 2022 Yahoo! Inc. All rights reserved"}) |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row
ready to start consuming query after 12 ms, results consumed after another 0 ms
neo4j@neo4j> match (a) <- [r:KEYWORD_ADDED_BY] - (b) return a,r,b;
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| a | r | b |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| (:source {name: "Yahoo News - Latest News & Headlines", url: "Yahoo News - Latest News & Headlines", organizaion: "Copyright (c) 2022 Yahoo! Inc. All rights reserved"}) | [:KEYWORD_ADDED_BY] | (:keyword {keyword: "TEST"}) |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row
ready to start consuming query after 9 ms, results consumed after another 1 ms

that second query should not respond like that, or at least I don't want it to do so.. I want the relationship in one direction only.. What did I do wrong with my initial match/create statement?

Thanks for the help as I'm lost on this one.. Previously I always created the node on one statement, and then the relationship on a separate statement.. And it works as expected (only a directional relationship is created).. I tried now to combine both operations into a single query and obviously I screwed up somewhere, I just don't know where..

  • Andre

Your second query to retrieve does not specify the direction, so you are getting two paths back, one in each direction. Note the values of a and b in each result.

Correct, but why are there two directions in the first place? i use the direction arrow when creating it, but as you can see it thinks it works in both directions and the two query's with the direction specifier do indeed seem to indicate that both directions are "in there" even though the last query should NOT return anything (or at least I do not want it to)

Ah, Thanks Gary.. From your comments I re-checked my query, and realized I didn't specify which nodes, so I'm guessing it was matching the node in both directions.. If I add in the nodes I'm checking in a & b then it works as expected..

Sorry for the stupid question, and thank you for taking the time to respond. It made me realize my own mistake :slight_smile:

  • Andre

I thought you would also get two results even if specifying the nodes when not specifying a direction. I experimented and found what you stated is true. Very interesting.

You should specify the direction though. I always find it best to add as much constrain to the pattern as you know.

No question is stupid....how else do we learn. I just learned something from your not-so-stupid question.

I will start explicitly stating the direction going forward. Thanks for the advice!