Gremlin date filter approach

后端 未结 1 1674
清酒与你
清酒与你 2021-01-21 07:12

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.

相关标签:
1条回答
  • 2021-01-21 07:46

    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.

    0 讨论(0)
提交回复
热议问题