Is there anyway to further simplify this query? I want to go from kingdom
to all the species
, there are nodes related towards the species nodes. The image shows the result of this query, but is there any way to match the kingdom
node and all the nodes and relationships until the species node. If you like: all nodes/relationships between kingdom and species.
There will never be a node not attached to the kingdom or species objects (it's a taxonomic hierarchy). The RELTYPE
will probably change to something more meaningful.
MATCH (k:Kingdom)-
[:RELTYPE]->(p:Phylum)-
[:RELTYPE]-(c:Class)-
[:RELTYPE]-(o:Order)-
[:RELTYPE]-(f:Family)-
[:RELTYPE]-(g:Genus)-
[:RELTYPE]-(s:Species)
RETURN k, p, c, o, f, g, s
You can use a variable length relationship in your query. *6 means you can get the nodes from Kingdom up to max of six hops (or relationships) until you reach Species. Then from this path, return all nodes that you found.
MATCH p=(:Kingdom)-[:RELTYPE*6]-(:Species)
RETURN nodes(p)
No need to specify the relationship types, but it is good practice to set an upper limit (even if it's a high one). For example:
MATCH p=(:Kingdom)-[*..15]->(:Species)
RETURN nodes(p)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.