Unable to add a relationship between existing nodes

Hi,
I did search for an answer and tried a few things before posting but, no luck.

I have created a fairly simple model (see capture below) about Music, Artists, Bands and Albums relationships. I was able to create the relations between Artists and Bands but unable to add a relationship between existing Bands and Albums.

Here's the code I've used:
MATCH (a:Band), (b:Album) WHERE a.name = "King Crimson" AND b.name = "In The Court Of The Crimson King"
CREATE (a)-[r: RELEASED]->(b)
RETURN a,b


I'm using Version 1.4.5 (1.4.5.55) of Neo4j desktop

I hope the is sufficient for you to help me do the right thing.
Regards,
Simon

Simon,

I replicated this on my own Desktop instance (running Neo4j 4.2.4) and it worked fine :

CREATE (a:Band {name: "King Crimson"}) return a
CREATE (b:Album {name: "In The Court Of The Crimson King"}) return b

MATCH (a:Band), (b:Album) WHERE a.name = "King Crimson" and b.name = "In The Court Of The Crimson King"
CREATE (a)-[r: RELEASED]->(b)
RETURN a,r,b

kingcrimsongraph

I'd still have thought you'd get something back when you return a and b (which should have MATCHed at the start of your query). Maybe you're not finding the nodes in the graph with your query? Both the property names and the matching text are case sensitive, and from the picture of the graph you have in your post I can't see the property names for the Band and Album nodes. Can you match and return those individual nodes without trying the create?

What's odd, though, is the visualisation does say there's one RELEASED relationship present in the query results (though I can't see one), and I can see in the 'Relationship Types' section of the Database Information pane that there's RELEASED relationships present in the DB. What do you get if you click that 'RELEASED' relationship label in the Database Information tab (it should run a query to get 25 random instances of the relationship from the DB)?

Thanks,

-JOE

Thanks so much Joe for the quick response.

Here’s some the info you’ve requested below.


Regards,
Simon

from the screenshot above the match (n:Album) .... is indicating the property name is 'Name' and not 'name'. So running

MATCH (a:Band), (b:Album) WHERE a.name = "King Crimson" AND b.name = "In The Court Of The Crimson King"
CREATE (a)-[r: RELEASED]->(b)
RETURN a,b

will not create the realtionship since there is no 'name' property of :Album nodes.

Change the cypher to

MATCH (a:Band), (b:Album) WHERE a.name = "King Crimson" AND b.Name = "In The Court Of The Crimson King"
CREATE (a)-[r: RELEASED]->(b)
RETURN a,b

though this pre-supposes that there is a 'name' property of ':Band' nodes? If the property is 'Name' then you will need to change WHERE a.name=.... to WHERE a.Name=.....

1 Like

Hi Dana,
You’re right on!
By mistake I’ve created 2 occurrences name and Name as displayed below.

I should have used the existing album_title instead :

Any suggestion to clean my little mess?

Thanks again for you help, I’m still very novice and learn by mistakes, borrowing code examples from different places


Merci beaucoup Dana!
Simon

from your screenshots I'm not seeing the label for said nodes. can you rerun the match statements but include/add labels(n) in the return clause

Hue this is what you meant?

correct. the prior screenshot which did not include labels(n) simply indicated there were a bunch of nodes with a property 'Name' or 'name' but it did not include the detail as to what label was associated with the node. This last screenshot provides this detail.
From the last screenshot we see the 4th row has a :Album labelled node with properties Name and Released and there is but 1 node with this.
Is your goal to simply rename all property names to be lowercase? If so then

match (n:Album) set n.name=n.Name, n.released=n.Released;
match (n:Album) remove n.Name, n.Released;

Thanks a lot Dana, it worked just fine.
I’ve learned a lot and will rebuild from scratch to have a clean slate, using csv to create all the ne pessary nodes.
Merci encore!
Simon