Gremlin date filter approach

谁都会走 提交于 2019-12-31 01:54: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:


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.



来源:https://stackoverflow.com/questions/20567483/gremlin-date-filter-approach

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!