Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-17-2020 07:18 AM
I recently started using neo4j and its query language "cypher" for working with building/metering data.
My current graph database consists of different nodes (with different labels such as: point,meter,elec,equip ..etc. just to name a few), and each having different properties (not relevant in this context).
What I would like to do, is to get a sub-graph of different nodes which have different labels. For instance I would like to get all the nodes labeled as "point" as well as the ones labeled "equip" and the ones labeled as "meter". To do so I tried the following query:
MATCH (p:point)
MATCH (e:equip)
MATCH (m:meter)
RETURN p, e, m
However that does not work since: This query builds a cartesian product between disconnected patterns.
I am trying to get these so that, if a node labeled "point" is connected to either an "equip" or "meter" node, I would get the relationship. If nothing is connected to the "point" node, it would just be stand alone. Therefore I could have one subgraph with the "point" to "meter"/"equip" connections and visually identify the isolated "point".
I also tried something like:
MATCH (p:point)--(e:equip)
RETURN p,e
But that only return the "point" nodes which are somewhat connected to an "equip" node. Not giving me the isolated nodes labeled "point" as well.
Looking forward to your input on this (simple case I guess).
Best!
Solved! Go to Solution.
09-18-2020 12:21 AM
Hello @thibaut.richert and welcome to the Neo4j community
OPTIONAL MATCH (p:point)--(e:equip)
RETURN p,e
Regards,
Cobra
09-18-2020 12:21 AM
Hello @thibaut.richert and welcome to the Neo4j community
OPTIONAL MATCH (p:point)--(e:equip)
RETURN p,e
Regards,
Cobra
09-18-2020 04:05 AM
Thank you very much, that solved my issue 🙂
09-20-2020 05:41 AM
If you are interested only in isolated points then you can also try
MATCH (p:point)
WHERE size((p)-->())=0 AND size((p)<--())=0
RETURN p
This will return only isolated points.
All the sessions of the conference are now available online