Hello - I have a set of nodes where multiple values within a property have been delimited by a semicolon. These nodes have relationships to other nodes already established. I would like to split the node up based on the delimiter and preserve the existing relationships. Clearly this should have been resolved prior to data load, however, there are multiple fields throughout my data set with the same issue and I'm keen on reconciling this.
Here's an example of the data with fields related to countries. This is stored in the label :Country with a property of "country".
"qa; us; ca; fr"
"kw; us"
I would like to split this to individual country codes so I've written this in Cypher:
MATCH (n:Country) WHERE EXISTS(n.country)
with n, split(n.country, ";") as countryarray
unwind countryarray as acountry
return n.country, trim(acountry);
That code returns a well behaved:
"qa; us; ca; fr" "qa"
"qa; us; ca; fr" "us"
"qa; us; ca; fr" "ca"
"qa; us; ca; fr" "fr"
"kw; us" "kw"
"kw; us" "us"
I have multiple other nodes that connect to the nodes with delimited properties. How can I take the split results and refactor the nodes to preserve the existing relationships?
Thank you and Happy New Year.