Filter Graph DB based on date field: I searched http://tinkerpop.apache.org/docs/current/reference/ but did not find a documentation for the same.
Did some research and it seems lt
, gt
, etc are working. BUT is my below approach the proper way? or is there a official way to do it?
Below code works on Neptune and NEO4J but is this Vendor Independent.
Also found a 4/5 yr old post where it was recommended to use long, but I think its pretty old.
Sample data:
g.addV("TestDate2").property("title", "Alpha").property("date", "01-19-2018")
g.addV("TestDate2").property("title", "Bravo").property("date", "02-20-2018")
g.addV("TestDate2").property("title", "Charlie").property("date", "03-13-2018")
g.addV("TestDate2").property("title", "Delta").property("date", "04-14-2018")
g.addV("TestDate2").property("title", "Echo").property("date", "05-15-2018")
g.addV("TestDate2").property("title", "Foxtrot").property("date", "06-16-2018")
g.addV("TestDate2").property("title", "Hotel").property("date", "07-17-2018")
g.addV("TestDate2").property("title", "India").property("date", "08-18-2018")
Queries:
(I formatted the data of output so it wont really match Gremlin output buts its more readability)
Less than
g.V().has("TestDate2", "date", lt("03-03-2018")).valueMap()
{'date': ['02-20-2018'], 'title': ['Bravo']}
{'date': ['01-19-2018'], 'title': ['Alpha']}
g.V().has("TestDate2", "date", lt("03-24-2018")).valueMap()
{'date': ['03-13-2018'], 'title': ['Charlie']}
{'date': ['02-20-2018'], 'title': ['Bravo']}
{'date': ['01-19-2018'], 'title': ['Alpha']}
Greater than
g.V().has("TestDate2", "date", gt("06-16-2018")).valueMap()
{'date': ['07-17-2018'], 'title': ['Hotel']}
{'date': ['08-18-2018'], 'title': ['India']}
g.V().has("TestDate2", "date", gte("06-16-2018")).valueMap()
{'date': ['07-17-2018'], 'title': ['Hotel']}
{'date': ['06-16-2018'], 'title': ['Foxtrot']}
{'date': ['08-18-2018'], 'title': ['India']}
Between filter
g.V().has("TestDate2", "date", between("04-01-2018", "07-01-2018")).valueMap()
{'date': ['06-16-2018'], 'title': ['Foxtrot']}
{'date': ['04-14-2018'], 'title': ['Delta']}
{'date': ['05-15-2018'], 'title': ['Echo']}
Fails, but its fine
g.V().has("TestDate2", "date", lt("3-3-2018")).valueMap()
{'date': ['03-13-2018'], 'title': ['Charlie']}
{'date': ['07-17-2018'], 'title': ['Hotel']}
{'date': ['02-20-2018'], 'title': ['Bravo']}
{'date': ['06-16-2018'], 'title': ['Foxtrot']}
{'date': ['04-14-2018'], 'title': ['Delta']}
{'date': ['08-18-2018'], 'title': ['India']}
{'date': ['01-19-2018'], 'title': ['Alpha']}
{'date': ['05-15-2018'], 'title': ['Echo']}