From the above graph, when i am trying to run the below query
MATCH (d:Account)-[:HAS_ACCOUNT]-(p:Person)-[r:Has_Share]->(ps:Person)<-[r1:Has_share]-(prel:Person)
with ps,d,p,r,prel,r1
WHERE d.Fraud='S' and p.P_id<>prel.p_id and size((ps)<-[:Has_Share]-(:Person)) <= 5
with ps,d,p,r,prel,r1,(case when r.date > r1.date then r.date else r1.date end) as recentdate
return
d.Account_id as fraud_account,
p.p_id as fraud_person,
prel.p_id as fraud_person,
recentdate as RECENTDATE
I am not getting the result. The reason behind i am not getting answer is probably because of the size operator, since the size of relation is counted as more than 5, hence records are not getting generated. But in actual case since there are only 5 person node is connected i should have to return all the 5 nodes.
Can anyone guide me on how i can return all the 5nodes despite having more then 5 relationships!!
If I can decipher your diagram correctly, you have 2 relationships from person with p_id=6 to person with p_id=2.
Next time, it would be great to have some non-diagram form of the example graph, like with Cypher's CREATE statements, so there is no guessing needed.
Also, I assume that you are on 3.x as size(<pattern>) is deprecated in 4.x and should be replaced with size of a pattern comprehension or in 5.x with COUNT { ... }.
This becomes a lot easier on 5.x with COUNT subquery expressions but this should do it:
MATCH (d:Account)-[:HAS_ACCOUNT]-(p:Person)-[r:Has_Share]->(ps:Person)<-[r1:Has_share]-(prel:Person)
WITH ps, d, p, r, prel, r1
WHERE d.Fraud='S' AND p.P_id <> prel.p_id
CALL {
WITH ps
MATCH (ps)<-[:Has_Share]-(other:Person)
WITH collect(DISTINCT other) as otherPersons
RETURN size(otherPersons) AS noOfOtherPersons
}
WITH ps, d, p, r, prel, r1,
(case when r.date > r1.date then r.date else r1.date end) as recentdate
WHERE noOfOtherPersons <= 5
RETURN
d.Account_id as fraud_account,
p.p_id as fraud_person,
prel.p_id as fraud_person2,
recentdate as RECENTDATE
since i don't have v5, i won't be able to run that statement.
But will it be possible to give some idea using V3.5?
I was trying MATCH (d:Account)-[:HAS_ACCOUNT]-(p:Person)-[r:HAS_SHARE]->(ps:Person)<-[r1:HAS_SHARE]-(prel:Person)
WHERE d.Fraud = 'S' AND p.P_id <> prel.P_id
MATCH (ps)<-[:HAS_SHARE]-(other:Person)
WITH ps, d, p, r, prel, r1, other,
CASE WHEN r.date > r1.date THEN r.date ELSE r1.date END AS recentdate,
COLLECT(DISTINCT other) AS otherPersons
WITH ps, d, p, r, prel, r1, recentdate,
SIZE(otherPersons) AS noOfOtherPersons
WHERE noOfOtherPersons <= 5
RETURN d.Account_id AS fraud_account,
p.P_id AS fraud_person,
prel.P_id AS fraud_person2,
recentdate AS RECENTDATE
but it seems it is also returning results when (Ps:Person) has more then 5 nodes connected, where as that should not be the case.
My primary focus is if PS:Person nodes is connected to more then 5, then it should ignore them but thats not happening.