Neo4J Get Data From Multiple Node with Multiple Relationship

95 views
Skip to first unread message

Alliance Ais

unread,
Apr 7, 2017, 3:20:44 AM4/7/17
to Neo4j
Hello Following My Neo4J Query to Get CheckIn or Review or Pixel etc. which is Given by User to Business.Which I got perfectly.but I want also Get Pulse which given By User but not given on Business. So My Following Query is not Get Pulse.

start n=node({otherUserId}) 
with n match (n)-[r1]-(p)-[r2]-(b:business) 
where r1.onPulse=true and r2.onPulse= true and 
('check_in' IN labels(p) OR 'tip' IN labels(p) OR 'review' IN labels(p) OR 'rate' IN labels(p)) 
with p,r1,r2,n,b 
optional match(p)-[r3:has_pix]-(pix:pix) 
OPTIONAL MATCH (p)-[tg]-(tags) 
where type(tg) in ['has_biz_tag', 'has_user_tag', 'has_hash_tag'] 
return n,r1,p,r2,r3

Above my Relationship node. I want Neo4J Query for that.


Also I asked in StackOverflow : http://stackoverflow.com/q/43271456/2893413

Michael Hunger

unread,
Apr 12, 2017, 3:49:10 PM4/12/17
to ne...@googlegroups.com
match (n)-[r1]->(p)-[r2]->(b:business) 
where id(n) = {otherUserId}
where r1
.onPulse=true and r2.onPulse= true and (p:check_in OR p:
tip OR p:review or p:rate)
optional match (n)-[:pulse_post]->(pulse)
optional match(p)-[r3:has_pix]->(pix:pix) 
OPTIONAL MATCH (p)-[tg:has_biz_tag|has_user_tag|has_hash_tag]->(tags) 
return n,r1,p,r2,r3,pix,tg,tags

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alliance Ais

unread,
Apr 26, 2017, 3:07:44 AM4/26/17
to Neo4j, Jigar Oza, sadikhasan...@gmail.com

Hi, Michael Hunger

Thanks for reply and your query helped us a lot but little issue we have that i am sharing with you please help us as we are near to complete project as we stuck above requirement.

Let me explain where we are getting issue.

Please refer above image, while we are using your query we are getting rate,review and tip but not getting pulse that is posted by system user, while talking about pulse one important thing i would like to share with you is pulse post done by user is not on venue[business]. where other activities [check-in, review, tip, rate] done on venue[business] by user.

while using your query its not getting pulse in the result set.

One more thing in final result set that we are getting from your query , how we can set order by date in descending order for whole result set.

We are waiting for your suggestion that so valuable for us.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
Message has been deleted

Kamal Murthy

unread,
Apr 26, 2017, 3:48:43 PM4/26/17
to Neo4j, ji...@aistechnolabs.us, sadikhasan...@gmail.com
Hi,

I added a variable 'p2' for pulse (shown in bold) in the optional match and added the same variable to the return list. Here is the query:

match (n)-[r1]->(p)-[r2]->(b:business) 
where id(n) = {otherUserId}

where r1.onPulse=true and r2.onPulse= true and 
(p:check_in OR p:tip OR p:review or p:rate) 
optional match (n)-[:pulse_post]->(p2:pulse)
optional match(p)-[r3:has_pix]->(pix:pix) 
OPTIONAL MATCH (p)-[tg:has_biz_tag|has_user_tag|has_hash_tag]->(tags) 
return n,r1,p,r2,r3,pix,tg,tags,p2

-Kamal

Alliance Ais

unread,
Apr 27, 2017, 2:08:29 AM4/27/17
to Neo4j, ji...@aistechnolabs.us, sadikhasan...@gmail.com
Thanks for given your valuable time. But We cannot fetch any pulse that you mentioned as p2 in cypher Query. We get only null value for p2. Please suggest us what we have to change in my Cypher Query?

Michael Hunger

unread,
Apr 27, 2017, 3:05:45 AM4/27/17
to ne...@googlegroups.com, ji...@aistechnolabs.us, sadikhasan...@gmail.com
Then check the relationship (type and direction) from n to pulse if it exists.

Michael

To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.

Alliance Ais

unread,
Apr 27, 2017, 3:14:20 AM4/27/17
to Neo4j, ji...@aistechnolabs.us, sadikhasan...@gmail.com

Hi, Michael Hunger

Thanks for reply. As i am bit new to neo4j so i am not getting you properly. Can you please help us by explaining more.

I am attaching image so that help you for understand our requirement.



Kamal Murthy

unread,
Apr 28, 2017, 3:08:04 AM4/28/17
to Neo4j

Kamal Murthy

unread,
Apr 28, 2017, 3:10:06 AM4/28/17
to Neo4j, ji...@aistechnolabs.us, sadikhasan...@gmail.com
Hi,
In the diagram it is shown that User node has a PIXEL_POST relationship with Pixel node. From the Cypher query the Check_In node has HAS_PIX relationship with Pixel node. I assume this is correct as you seem to get the results with your queries.

Created a Neo4j graph database from your Cypher query. I created two user nodes with id 1 and 2. User with id = 1 only has PULSE_POST relationship with Pulse node. For this test, User with id = 2 has no PULSE_POST relationship. Here is my Cypher query:

CREATE (cpny:Company {name: "Company"})
//User id = 1
CREATE (usr:User {id: 1})
CREATE (cpny)-[:USER]->(usr)
CREATE (pxl:Pixel {id: 1})
CREATE (plse:Pulse {id: 1})
CREATE (usr)-[:PULSE_POST]->(plse)
CREATE (chkin:CheckIn {id: 1})
CREATE (tags:Tag {id: 1})
CREATE (usr)-[:CHECKIN_POST {onPulse:true}]->(chkin)
CREATE (chkin)-[:HAS_PIX {onPulse:true}]->(pxl)
CREATE (chkin)-[:HAS_BIZ_TAG]->(tags)
CREATE (venu:Venue {id: 1})
CREATE (chkin)-[:CHECKIN_ON]->(venu)
CREATE (pxl)-[:PIXEL_ON]->(venu)

//User id = 2
CREATE (usr2:User {id: 2})
CREATE (cpny)-[:USER]->(usr2)
CREATE (px2:Pixel {id: 2})
CREATE (chkin2:CheckIn {id: 2})
CREATE (tags2:Tag {id: 2})
CREATE (usr2)-[:CHECKIN_POST {onPulse:true}]->(chkin2)
CREATE (chkin2)-[:HAS_PIX {onPulse:true}]->(px2)
CREATE (chkin2)-[:HAS_USER_TAG]->(tags2)
CREATE (venu2:Venue {id: 2})
CREATE (chkin2)-[:CHECKIN_ON]->(venu2)
CREATE (px2)-[:PIXEL_ON]->(venu2)
;

graph:


Query on User id = 1:

MATCH (c)-[r0]->(n)-[r1]->(p)-[r2]->(b:Venue)
WHERE n.id = 1
optional match (n)-[r3:PULSE_POST]->(p2:Pulse)
optional match (p)-[r4:HAS_BIZ_TAG|HAS_USER_TAG]->(t:Tag)
RETURN c, r0, n, r1, p, r2, b, p2, r4, t;

graph:


You see Pulse node (yellow color).

Query on User id = 2:

MATCH (c)-[r0]->(n)-[r1]->(p)-[r2]->(b:Venue)
WHERE n.id = 2
optional match (n)-[r3:PULSE_POST]->(p2:Pulse)
optional match (p)-[r4:HAS_BIZ_TAG|HAS_USER_TAG]->(t:Tag)
RETURN c, r0, n, r1, p, r2, b, p2, r4, t;

graph:



User id = 2 has no relationship with Pulse. Running this query:
MATCH (n)-[r3:PULSE_POST]->(p2:Pulse)
RETURN n, r3, p2;

graph:


Again only User with id = 1 shows the Pulse node!


As Michael mentioned, you seem to have nodes with no relationship to Pulse node. Run the above query and send me the screenshot and that will help me to figure out the issue. Actually, run this query:  call apoc.meta.graph() and send me the screenshot.

-Kamal
Reply all
Reply to author
Forward
0 new messages