Gremlin date filter approach
Asked Answered
T

1

3

Is there anyway to query on date in titan/gremlin? e.g. find all results in the last X days

Any help would be much appreciated.

Trucker answered 13/12, 2013 at 13:16 Comment(0)
R
3

The best approach is to simply store the date as a Long value and to possibly index upon such a field in an edge such that you could take advantage of limit(), interval, etc. See this Titan wiki page on the topic:

https://github.com/thinkaurelius/titan/wiki/Vertex-Centric-Indices

It maps to your specific request with a Twitter example where it indexes on time. You could find results based on time by simply calculating milliseconds for "X days" back and then finding all results that come after that:

g.v(1).outE.has('time',T.gte, fiveDaysAgoInMs).inV

Note that as of Titan 0.4.1 you can also define the directionality of the index such that newest items are returned first (no need to reverse index the property anymore):

https://github.com/thinkaurelius/titan/wiki/Type-Definition-Overview#sortkeytitantype-and-signaturetitantype

Also, if you don't mind a little denormalization you could also store the date as a sortable String value (iso-8601 for example) in addition to the Long value. That helps you easily see what a date is without extra conversion.

Randellrandene answered 13/12, 2013 at 16:11 Comment(1)
Thanks a bunch! I will try and let you know how it goes.Trucker

© 2022 - 2024 — McMap. All rights reserved.