1
votes

I am trying to create a gremlin query for AWS Neptune which checks for a particular property on a node (lastUpdated) and returns all nodes that have value smaller than a certain number. lastUpdated is epoch timestamp in this case, and I am trying to find all nodes which have lastUpdated 90 days less than current timestamp.

Here is the query that I wrote:

g.V().hasLabel('nodelabel').hasNot('lastUpdated',P.gt(1544916150)).count()

To make this query dynamic, so that whenever it is fired, I get all nodes more than 90 days old, I changed it to following:

g.V().hasLabel('nodelabel').has('lastUpdated',not(P.gt(1552798296-7776000))).count()

where 1552798296 is current_date and 7776000 is number of seconds in 90 days

Apparently, subtraction is not that straightforward in Gremlin. Any hints/suggestions on how I can write this gremlin query?

Thanks

1

1 Answers

1
votes

TinkerPop introduced a math() step a few point releases back.

You could do something like this:

gremlin> g.V().has('n').valueMap(true)
==>[id:58855,label:test,n:[5]]
==>[id:58857,label:test,n:[10]]  

gremlin> g.V().values('n')
==>5
==>10

gremlin> g.V().values('n').math('_ -5')
==>0.0
==>5.0

gremlin> g.V().where(values('n').math('_ -5').is(gt(0)))
==>v[58857]