When I want to create a relationship between district and state after running the following Cypher query
Load csv with headers from 'file:///Congresional_Directory_Updated.csv' as line
With line
MERGE (district:District{District:line.`St/Dis`})
MERGE (city:City{Name:line.City})
MERGE (district)-[:Located_In]->(city)
As you can see there are now multiple "Located_In" relationships that I didn't intend on having in my model. To be clear the desired "Located_In" relationships are between District and State as well as between City and State. I have circled them in the below image.
I'm a little confused. From your query you have: MERGE (district)-[:Located_In]->(city)
which you said is something you don't want?
I don't see the MERGE for district located in the state.
Separately, please be aware that MERGE (city:City{Name:line.City}) is likely not what you want, as there are many cities with the same names that are in different states (Springfield, for example).
If you want to create your cities per state, then you need to do this instead:
thanks for your response and I really appreciate the heads up on cities with the same name, I apologies I made an error in my previous post.
I have circled the relationships I want below, I would appreciate your advice on how to avoid the ones I don't want.
Let's see...you don't explicitly have an relationship MERGEs between a :District and a :State in your query, but you do have a curious (:City)-[:Located_In]->(:City) relationship in your graph that I'm guessing you aren't expecting to be there.
Is there by chance a :City node that is also labeled as a :State, such that it was caught up in a MATCH as something other than what it was meant to be?
MATCH (problem:City:State)
RETURN problem, problem.Name
That could explain both of the odd relationships being returned.
Otherwise, just look for the pattern that isn't supposed to be there and figure out if it's an outliner:
MATCH (d:District)-[:Located_In]->(s:State)
RETURN count(*)
And from there investigate further, and check the actual nodes and rels involved against your query and the CSV.
I ran both query and they returned no records and a count of 0. Thanks for your time and help. There isnt a issue with the data in the database so Im happy enough that whatever error that's causing this funny Schema isnt that big of a deal.
Can you also let us know what version of Neo4j you're using? I had thought we had fixed that bug earlier, but if it's still around we'll want to pass that along to engineering for fixing.