Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Too many relationships being returned

Tags:

neo4j

cypher

Disclaimer: I'm a beginner to neo4j. I've walked through the tutorial. I've built my data, and loaded it into a graphdb and I'm trying to validate that it imported correctly.

I'm not sure if the problem I'm having is something I'm doing in the import or in the cypher query.

I'm using this import tool to import the following files (the below has been filtered to just contain the rows I'm currently investigating):

application_id node file:

application_id:ID(application_id),:LABEL
2036983247,application_id
2037028183,application_id

personal_phone node file:

personal_phone:ID(personal_phone),:LABEL    
5555551234,personal_phone

relationship file:

:START_ID(personal_phone),:END_ID(application_id),:TYPE
5555551234,2036983247,APPLIED
5555551234,2037028183,APPLIED

My cypher query:

match p= (a {personal_phone:'5555551234'}) -->(b) return p

In my results I see that the personal_phone node has 2 'APPLIED' relationships with each of the application_id nodes. I'd expect to see only one. Where am I going wrong?

EDIT : This is what I see. The center node is the personal_phone node.

enter image description here

EDIT 2 : So I figured out that using the dump statement from the neo4j shell I could get an export of the database. I figured I'd run it for the nodes in question:

$ dump match p= (a personal_phone:'5555551234'})-->(b) return p;

Returns:

begin
create (_5:`application_id` {`application_id`:"2036983247"})
create (_410:`application_id` {`application_id`:"2037028183"})
create (_6928:`personal_phone` {`personal_phone`:"5555551234"})
create _6928-[:`APPLIED`]->_410
create _6928-[:`APPLIED`]->_5
create _6928-[:`APPLIED`]->_410
create _6928-[:`APPLIED`]->_5
;
commit

This shows that I definitely have duplicate relationships. Any ideas on how I can fix this?

like image 719
Robert Penridge Avatar asked Jul 02 '15 20:07

Robert Penridge


2 Answers

You add two APPLIED relationships from a single personal_phone node to two different application_id nodes.

When you MATCH all relationships from this personal_phone node, you would indeed expect to get two APPLIED relationships as result.

like image 64
Martin Preusse Avatar answered Oct 24 '22 18:10

Martin Preusse


Ugh - dumb mistake in my import was the issue. It went unnoticed because there were soo many different files being imported but basically I had the relationships file importing twice in my script file:

--relationships "f:\temp\r_personal_phone_application_id_APPLIED.csv" 
--relationships "f:\temp\r_personal_phone_application_id_APPLIED.csv" 
like image 27
Robert Penridge Avatar answered Oct 24 '22 19:10

Robert Penridge