Search code examples
javagremlinjanusgraph

Gremlin query to get vertices starting with a prefix


I am trying to fetch vertices that start with a specific prefixes in JAVA. I have used the between predicate. Is there a better way to do the same. For example if I need the vertices starting with 'a'. I would use

.has(label, propertyKey, P.between("a", "b"))


Solution

  • Since the release of TinkerPop 3.4.0, Gremlin also supports simple text predicates

    In this case, you should use startingWith.

    .has(label, propertyKey, TextP.startingWith("a"))
    

    example: https://gremlify.com/ad