1

Lets say I have the following Gremlin graph:

g.addV('test1').property('pkey', 100).property('v1', 100).property('v2', 150)
g.addV('test1').property('pkey', 100).property('v1', 100).property('v2', 75)

I want to query for all of the 'test1' labeled vertices where the property value v1 is greater than the property value v2. How do I achieve this in Gremlin?

John
  • 3,451
  • 2
  • 16
  • 7

1 Answers1

3

You can use where() step in this fashion:

gremlin> g.addV('test1').property('pkey', 100).property('v1', 100).property('v2', 150)
==>v[0]
gremlin> g.addV('test1').property('pkey', 100).property('v1', 100).property('v2', 75)
==>v[4]
gremlin> g.V().hasLabel('test1').as('a').where('a',gt('a')).by('v1').by('v2')
==>v[4]
gremlin> g.V().hasLabel('test1').as('a').where(gt('a')).by('v1').by('v2')
==>v[4]
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • Does this work for you against CosmosDB's Gremlin API? I just tried that, and it returned an empty list. g.V().hasLabel('test1').valueMap(): ``` [ { "pkey": [ 100 ], "v1": [ 100 ], "v2": [ 150 ] }, { "pkey": [ 100 ], "v1": [ 100 ], "v2": [ 75 ] } ] ``` g.V().hasLabel('test1').as('a').where(gt('a')).by('v1').by('v2'): – John May 08 '19 at 04:44
  • i included the longhand version where you explicitly specify the initial comparing step label for `where()` - perhaps that works with CosmosDB? if that doesn't work you might need to raise a bug report to them. – stephen mallette May 08 '19 at 10:22