Reputation: 1456
In gremlin I have such query:
g.V().match(
__.as('a').outE('x').as('a_x_b').inV().as('b'),
__.as('a').outE('x1').as('a_x1_b').inV().as('b'),
__.as('a').outE('x2').as('a_x2_b').inV().as('b'),
__.as('b').outE('know').as('b_knows_c').inV().as('c'),
__.as('b').outE('know1').as('b_knows1_c').inV().as('c')
).select('a','b','c', 'a_x_b', 'a_x1_b', 'b_knows1_c', 'a_x2_b')
But it is and
logic. I want to using or
in g
such like
g.V().match(
or(__.as('a').outE('x').as('a_x_b').inV().as('b'),
__.as('a').outE('x1').as('a_x1_b').inV().as('b'),
__.as('a').outE('x2').as('a_x2_b').inV().as('b')),
or(__.as('b').outE('know').as('b_knows_c').inV().as('c'),
__.as('b').outE('know1').as('b_knows1_c').inV().as('c'))
).select('a','b','c', 'a_x_b', 'a_x1_b', 'b_knows1_c', 'a_x2_b')
I think there is no such thing at gremlin. Why I need such thing. Because the one property of edge don't support multi value like the vertex. I want such multi value in one edge, So I must using multi label. Then I need to filter such label edge but using the or
logic.
In another way: how to choose some edge label from multi label?
I figure out to such answer.
g.V().match(
__.as('a').outE().as('a_x_b').filter(or(hasLabel('x'), hasLabel('x2'))).inV().as('b'),
__.as('b').outE().as('b_know_c').filter(or(hasLabel('know'), hasLabel('know1'))).inV().as('c')
).select('a','b','c', 'a_x_b', 'b_know_c')
still open the question for more methods.
turn label to property is ok too.
g.V().match(
__.as('a').outE('x4').as('a_x_b').where(or(has('tag1', 1), has('tag2', 1))).inV().as('b'),
__.as('b').outE().as('b_know_c').filter(or(hasLabel('know'), hasLabel('know1'))).inV().as('c')).select('a','b','c', 'a_x_b', 'b_know_c')
Upvotes: 0
Views: 128
Reputation: 14371
A few observations:
match
step. It often leads to inefficient query execution. Pretty much everything you can do with a match
can also be done using where
steps.or
logic here. You can provide multiple labels to steps like outE
and hasLabel
. For example:gremlin> g.V(44).inE().label()
==>contains
==>contains
==>route
==>route
==>route
==>route
==>extra
gremlin> g.V(44).inE('extra','contains')
==>e[61286][8-extra->44]
==>e[57826][3743-contains->44]
==>e[54323][3729-contains->44]
gremlin> g.V(44).inE().hasLabel('extra','contains')
==>e[61286][8-extra->44]
==>e[57826][3743-contains->44]
==>e[54323][3729-contains->44]
Upvotes: 1