dondon
dondon

Reputation: 105

Filter gremlin path by label and property

I want to find all transitive relations (regardless of direction) by numbers of hops (2) with this traversal:

g.V(1).repeat(both()).times(2).path()

The result will look something like this:

==>[v[1], v[2], v[3]]

If I use by(label()) at the end of path():

==>[A, B, C]

If I use by('name'):

==>[R2, R1, R3]

But I cannot figure out how to mix the label and name together in the path result like this:

==>[A.R2, B.R1, C.R3]

I can already achieve the desired result with Java, but it costs a lot of iterations, converts and the performance is not great. Therefore I want to know if there is a native gremlin way to do this.

Upvotes: 1

Views: 754

Answers (1)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

There's no support for String concatenation in TinkerPop, but you could do something like this:

g.V(1).
  repeat(both()).
    times(2).
  path().
    by(union(label(), values("name")).fold())

Upvotes: 0

Related Questions