dateTime range query

385 Views Asked by At

In my ML8 database there are some JSON documents containing Dtm fields. An example you can see below at 'Data:'. I have an element range index of scalar type dateTime on this field and to check if that works I use the query you see below at 'Test:'. The results are as expected.

Now when I try to query this, I want to grab all documents with a Dtm field past a certain date, this query returns nothing. You can see the query below at 'Query:'.

Data:

"Dtm": "2015-06-25T07:11:10.0Z"

Query:

var date = xs.dateTime("2015-06-01T14:38:09.145231+02:00");
var b    = cts.elementRangeQuery("Dtm", ">", date);
var c    = cts.search(b);
c

Test:

cts.elementValues([xs.QName("Dtm")], null, ['limit=3'], null, 1.0, null);

TestResult:

2015-06-11T17:43:36
2015-06-11T17:43:37
2015-06-11T17:43:38
2

There are 2 best solutions below

4
On BEST ANSWER

Try using a cts.jsonPropertyRangeQuery, and use fn.subsequence to grab just one page of results instead of all. For example like this:

var date = "2015-06-16T07:11:10.0Z";
var b    = cts.jsonPropertyRangeQuery("Dtm", ">", date);
var c    = fn.subsequence(cts.search(b, ['unfiltered']), 1, 10);

HTH!

2
On

This is the final code to get this working.

var date = "2015-06-16T07:11:10.0Z";
var b    = cts.jsonPropertyRangeQuery("Dtm", ">", date);
var c    = fn.subsequence(cts.search(b, ['unfiltered']), 1, 10);

Thanks to @grtjn.