Search code examples
gremlinjanusgraphgremlin-servergremlinpython

Gremlin - How to filter edges on property when getting shortest path


The following query searches for the set of shortest paths from a given vertex (377524408) to another vertex that has an edge with the property test_property, and exits after 3 iterations (i.e. if no vertex is found on 3 traverses, we return no paths).

s.V(377524408).repeat(both().simplePath())
    .until(or(__.bothE().has('test_feature', gt(0)), 
              loops().is(lt(4))))
    .path().dedup().toList()

However, I want to filter the edges on which the above query traverses.

For example, only traverse edges that have a property filter_property < 100. How would I modify the above query to include this edge filter?


Solution

  • Instead of both().simplePath() you would use bothE().has('filter_property', lt(100)).otherV().

    Also, note, that loops().is(lt(4)) will always evaluate true in the first iteration. You probably want that to be loops().is(3).