Query recursive relationship chains in Neo4j with Cypher

I have a graph database that models the metadata for messages and the fields that may be contained in these messages. Some of these fields may be β€œgroups,” which are groups of other fields. I'm trying to ask Neo, "what messages use this group?" The following is a list of path types that you can use to receive a message from a group:

message-[:INLINE]->group (the fields of a group are used inline on a message) message-[:FIELDREF]->(fref)-[:FIELD]->(field)-[:DATATYPE]->group (the group is used as a data type by a field on the message) 

The second chain is recursive. In other words, the segment - [: FIELDREF] β†’ (fref) - [: FIELD] β†’ (field) - [: DATATYPE] - (group) can be repeated again and again, before finally reaching the group of interest to me.

So, I want to know how I can request a duplicate chain of relationships, and not just a few (like * after the relationship name) for each individual element in the path?

To conclude, you can either go to the group from the message by going to the [: INLINE] link, which can then follow the n number of "fieldref-field-datatype-group" chains. OR you can go to the group from the message by moving n number of chains "fieldref-field-datatype-group".

 START group=node({sourceGroupId}) ... ? ? ? ... 

So I want something like [?: INLINE] β†’ 0..n nets (fieldref-field-datatype-group).

Any thoughts?

+2
source share
1 answer

According to the Cypher link at http://docs.neo4j.org/chunked/milestone/query-match.html ...

12.2.13. Length Length Ratio Nodes that are a variable number of ratios β†’ node are deleted can be found using the following syntax: - [: TYPE * minHops..maxHops] β†’. minHops and maxHops are optional and default to 1 and infinity, respectively. When no ratings are given, points may be omitted.

An example of what I think you are looking for is below. I set at least two.

 start n=node:node_auto_index(name='Neo') match n-[r:KNOWS*2..]-m return n as Neo,r,m 

You can check this request verbatim at http://console.neo4j.org

+4
source

All Articles