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.
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.
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.