Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-10-2022 04:43 AM
hello,
I am a Neo4j newbie.
I have a Neo4j graph with 3 entities: Person, FirstName, Postcode - they are related to each other as follows:
Person -> [:HasFirstName] -> FirstName
Person -> [:HasPostcode] -> Postcode
I have a person in the database:
Tom with Postcode: LA2 0RN
I have this query:
06-10-2022 06:34 AM
I believe it is due there not existing a path between Person Tom and FirstName "Jerry", so the value of 'f' never get set, so the Cartesian product in your match has not results. The following should work:
MATCH(p:Person)
optional match (pc:Postcode{value:'LA2 0RN'})
optional match (f:FirstName{value: "Jerry"})
WHERE
exists((p)-[:HAS_POSTCODE] -> (pc))
OR exists((p)-[:HAS_FIRST_NAME]->(f))
return DISTINCT p, pc
Just a note, the data model seems a little strange. Typically, postal code and first name would be a property on the Person node. Is there a reason you have made this nodes instead?
06-10-2022 06:42 AM
Thanks for your response. We did have them as properties but when the graph was scaled its performance degraded (despite using indexes etc). We are trying a new model where we have extracted the properties that we search against into entities.
06-10-2022 07:48 AM
That is interesting that it degraded. With your new model, I am afraid you will get super nodes with all the common postal codes and first names people will have. Even if it finds the postal code or first name node quickly, it will have to traverse every relationship to collect the nodes on the other end. It's going to repeat this for each property extracted to a node. If you and all these conditions, it will have to find the intersection of all these nodes. It will be interesting to see how it performs.
06-13-2022 05:41 PM - edited 06-13-2022 05:45 PM
Our assumption is that it should reduce/filter the set of results if we extract values that we are searching against into entities. Preliminary findings confirm this however we will continue to test the hypotheses and keep you posted. Thank you for your assistance.
All the sessions of the conference are now available online