performance - How to fetch a subgraph of first neighbors in neo4j? -


i fetch first n neighbors of node query in neo4j: (in example, n = 6)

i have weighted graph, , order results weight:

start start_node=node(1859988) match start_node-[rel]-(neighbor) return distinct neighbor, rel.weight weight order proximity desc limit 6; 

i fetch whole subgraph, including second neighbors (first neighbors of first 6 children).

i tried smtg :

start start_node=node(1859988) match start_node-[rel]-(neighbor) foreach (neighbor | match neighbor-[rel2]-(neighbor2) ) return distinct neighbor1, neighbor2, rel.proximity proximity order proximity desc limit 6, rel2.proximity proximity order proximity desc limit 6; 

the syntax still wrong uncertain output: have table of tuples parent, children , weight: [node_a - node_b - weight]

i see if performing better 1 query or 6 queries. can in clarifying how iterate query (foreach) , format output?

thank you!

ok, think understand. here's attempt based on comment:

match (start_node)-[rel]-(neighbor) id(start_node) in {source_ids}   neighbor, rel order rel.proximity   collect({neighbor: neighbor, rel: rel})[0..6] neighbors_and_rels unwind neighbors_and_rels neighbor_and_rel   neighbor_and_rel.neighbor neighbor,   neighbor_and_rel.rel rel match neighbor-[rel2]-(neighbor2)   neighbor,   rel,   neighbor2,   rel2 order rel.proximity   neighbor,   rel,   collect([neighbor2, rel2])[0..6] neighbors_and_rels2 unwind neighbors_and_rels2 neighbor_and_rel2 return   neighbor,   rel,   neighbor_and_rel2[0] neighbor2,   neighbor_and_rel2[1] rel2 

it's bit long, gives idea @ least


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -