Gremlin日期筛选器方法 [英] Gremlin date filter approach
问题描述
反正在titan/gremlin中查询日期吗? 例如查找最近X天的所有结果
Is there anyway to query on date in titan/gremlin? e.g. find all results in the last X days
任何帮助将不胜感激.
推荐答案
最好的方法是简单地将日期存储为Long值,并可能在边缘的此类字段上建立索引,以便您可以利用interval
等.有关主题,请参见此Titan Wiki页面:
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-中心指数
它通过Twitter示例映射到您的特定请求,该示例在time
上建立索引.您可以根据time
找到结果,只需简单地计算"X天"的毫秒数,然后找到之后的所有结果:
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
请注意,从Titan 0.4.1开始,您还可以定义索引的方向性,以便首先返回最新项(不再需要对属性进行反向索引):
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):
此外,如果您不介意进行一些非规范化处理,则还可以将日期存储为可排序的字符串值( iso-8601 ).这可以帮助您轻松地查看日期,而无需进行额外的转换.
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.
这篇关于Gremlin日期筛选器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!