Skip to content

Instantly share code, notes, and snippets.

@aurbano
Last active December 5, 2016 15:06
Show Gist options
  • Save aurbano/48fb6827e961b0be34c5 to your computer and use it in GitHub Desktop.
Save aurbano/48fb6827e961b0be34c5 to your computer and use it in GitHub Desktop.
Neo4j: Return paths that contain only 1 node with a given property
// Match all the paths you are interested in, store them as p
// then set n.property to the appropriate value.
// the final 1 means how many nodes with that property/value you want in the paths
MATCH p=(c)-[:REL_TYPE*]-(n)
WHERE LENGTH(FILTER(n IN EXTRACT(n IN nodes(p) | n) WHERE n.property = "value"))=1
RETURN DISTINCT n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment