0
votes

I want to query marklogic for the documents which have been updated in last 3 minutes in a collection.

I have tried to write a structured query for the requirement but its accepting only hard-coded value for dateTime and not fn:current-dateTime() function. Below is what i tried.

<query xmlns="http://marklogic.com/appservices/search">
    <and-query>
         <collection-query>
             <uri>live</uri>
         </collection-query>
         <range-query type="xs:dateTime">
             <element ns="" name="created-on"/>
             <value>2019-06-10T10:36:14.002101Z</value>
             <range-operator>GT</range-operator>
         </range-query>
    </and-query>
</query>

I expect something like this -

<query xmlns="http://marklogic.com/appservices/search">
    <and-query>
         <collection-query>
             <uri>live</uri>
         </collection-query>
         <range-query type="xs:dateTime">
             <element ns="" name="created-on"/>
             <value>{fn:current-dateTime() - xs:dayTimeDuration("PT3M")}</value>
             <range-operator>GT</range-operator>
         </range-query>
    </and-query>
</query>
1

1 Answers

1
votes

You can use Expression Language to populate the current time in whatever format you want in the Query property of the QueryMarklogic processor.

Something like:

<query xmlns="http://marklogic.com/appservices/search">
    <and-query>
         <collection-query>
             <uri>live</uri>
         </collection-query>
         <range-query type="xs:dateTime">
             <element ns="" name="created-on"/>
             <value>${now():minus(180000):format('YYYY-MM-dd HH:mm:ss.SSS')}</value>
             <range-operator>GT</range-operator>
         </range-query>
    </and-query>
</query>

That expression gets the current time via now(), subtracts 3 minutes (3 min * 60 seconds/min * 1000 milliseconds/second = 180000 milliseconds) via minus(), and then expresses the date in a specific format. You can change that output to be whatever you need using the Java SimpleDateFormat codes.