Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filter paths by relationship property condition
/*
* Cypher query:
* MATCH p=(michael:Person { name: "Michael" })-[r:LIKES]->(people)
* WHERE r.weight >= 5
* RETURN p
*/
Transaction tx = db.beginTx();
Node michael = db.findNodesByLabelAndProperty(DynamicLabel.label("Person"), "name", "Michael").iterator().next();
List<Path> results = IteratorUtil.asCollection(db.traversalDescription()
.depthFirst()
.relationships(withName("LIKES"), Direction.OUTGOING)
.evaluator(Evaluators.fromDepth(1))
.evaluator(Evaluators.toDepth(1))
.traverse(michael))
.stream()
.filter(path -> ((Integer)path.lastRelationship().getProperty("weight")) >= 5)
.collect(Collectors.toList());
tx.success();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment