0
votes

Due to a unforeseen shutdown (and /or and error in my code) I have relationships in the database without nodes attached to it.

I think what happened was that used a MATCH statement to look up a node and subsequently a MERGE to create a relationship. For some reasons however the Match did not return a results, but the MERGE did create a relationship (apparently with a non existing node). See example below:

MATCH (image:Image {id:{param}.id}) FOREACH (tagName in {param}.tags | MERGE (tag:Tag {tag:tagName}) MERGE (image)-[:IS_TAGGED_AS]->(tag) // Here it creates a relationship even if no matching image is found. )

When I run a simple query I receive the following message:

While loading relationships for Node[xx] a Relationship[xx] was encountered that had startNode: 0 and endNode: 0, i.e. which had neither start nor end node as the node we're loading relationships for

I can reference the node and the relationship by Id (although the relationship does not return results) but can't Delete them.

Is there anything I can do to fix this?

Ideally I create a query to select all 'bad' relationships and delete them.

I am working on Neo4j 2.3.0.

1
How did you create the image nodes before? How many of those statements did you run? Just one? Can you run a consistency check on your store? markhneedham.com/blog/2014/01/22/…Michael Hunger
Why did your server crash?Michael Hunger
hi, Thanks for your suggestion. I downloaded the enterprise version and ran the consistency check....The problem is as I suspected, due to a bug in my code a lot of non existent nodes where connected resulting in 2016-02-19 10:03:22.822+0100 WARN [o.n.c.ConsistencyCheckService] Inconsistencies found: ConsistencySummaryStatistics{ Number of errors: 634345 Number of warnings: 0 Number of inconsistent NODE records: 436911 Number of inconsistent RELATIONSHIP records: 90981 Number of inconsistent RELATIONSHIP_GROUP records: 106419 Number of inconsistent COUNTS records: 34 }user2300301

1 Answers

0
votes

Are you sure that relationships can be created without nodes? That doesn't make sense to me. The way MERGE works is that it will match a node or relationship if it exists, otherwise it will try create a new one.

If you add PROFILE to the start of your query in the Neo4j Browser, you can see the execution plan for a query. You will see that nodes are matched first and then the relationships are matched and/or created afterwards.