Skip to content

Instantly share code, notes, and snippets.

@halftermeyer
Last active September 20, 2023 14:14
Show Gist options
  • Save halftermeyer/4841ef76830fa58a03f8d62c8d760d88 to your computer and use it in GitHub Desktop.
Save halftermeyer/4841ef76830fa58a03f8d62c8d760d88 to your computer and use it in GitHub Desktop.
Cypher pre-v5 fraud ring detection query
// Produce any 2-to-6-hop-long path
MATCH path=(a:Account)-[rel:TRANSACTION*2..6]->(a)
// Then filter to keep only
// - non-node-repeating paths (using some APOC magic)
WHERE size(apoc.coll.toSet(nodes(path))) = size(nodes(path)) - 1
// - and, at each step…
AND ALL(idx in range(0, size(rel)-2)
// … date-consistent
WHERE (rel[idx]).date < (rel[idx+1]).date
// … and 20%-rule compliant paths
AND tx[idx].amount >= tx[idx+1].amount >= 0.80 * tx[idx].amount
)
// Return all paths
RETURN path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment