I think the issue is in how you write the reference to the element you want to query. You write cts:element-attribute-range-query(xs:QName("PUBLICATION-DATE”), but like Chris is suggesting, you better write xs:QName("PUBLICATION-DATE”) as fn:QName(“http://www.incisivemedia.com/summary”, “PUBLICATION-DATE”), or you should declare a namespace prefix in your code, and use that in xs:QName:
declare namespace sum = “http://www.incisivemedia.com/summary”; xs:QName(“sum:PUBLICATION-DATE") Cheers From: <general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>> on behalf of Kari Cowan <kco...@alm.com<mailto:kco...@alm.com>> Reply-To: MarkLogic Developer Discussion <general@developer.marklogic.com<mailto:general@developer.marklogic.com>> Date: Friday, September 22, 2017 at 11:02 PM To: MarkLogic Developer Discussion <general@developer.marklogic.com<mailto:general@developer.marklogic.com>> Subject: Re: [MarkLogic Dev General] Querying DateTime values Let me get your opinion on this. I confirmed that there IS a dateTime element-attribute range index. Where the query works correctly, the data is written like this representation: <DOC-SUMMARY xmlns="http://www.incisivemedia.com/summary"> <PUBLICATION-DATE date="2017-08-09" datetime="2017-08-09T15:14:00-04:00">2017-08-09 15:14:00:000</PUBLICATION-DATE> </DOC-SUMMARY> Where it fails, the data is written this way - note the namespace precedes the declaration - which seems wrong to me. If it's right or wrong, can you advise if that needs to be updated or if there's a way to run the query to check a date range, returning docs within say the last 10 days only? <summary:DOC-SUMMARY xmlns:summary="http://www.incisivemedia.com/summary"> <summary:PUBLICATION-DATE date="2017-09-21" datetime="2017-09-21T17:47:00Z">2017-09-21T17:47:00Z</summary:PUBLICATION-DATE> </summary:DOC-SUMMARY> On Fri, Sep 22, 2017 at 1:05 PM, Kari Cowan <kco...@alm.com<mailto:kco...@alm.com>> wrote: Ahh, once i fixed the misplaced paren, I can get back a proper error that tells me something more useful -- No dateTime element-attribute range index for fn:QName("", "PUBLICATION-DATE") fn:QName("", "datetime") Thanks! - I think I know where to go from here :) XDMP-ELEMATTRRIDXNOTFOUND: cts:search(fn:collection(), cts:and-query((cts:directory-query("/data-sources/sbm/", "infinity"), cts:or-query((cts:element-query(xs:QName("sum:PUBLICATION-NAME"), cts:word-query("BenefitsPro.com", ("lang=en"), 1), ()), cts:element-query(xs:QName("sum:PUBLICATION-NAME"), cts:word-query("CUTimes", ("lang=en"), 1), ()), cts:element-query(xs:QName("sum:PUBLICATION-NAME"), cts:word-query("Treasury & Risk", ("lang=en"), 1), ()), ...)), cts:element-attribute-range-query(fn:QName("", "PUBLICATION-DATE"), fn:QName("", "datetime"), ">=", xs:dateTime("2017-08-23T23:59:00Z"), (), 1)), ())) -- No dateTime element-attribute range index for fn:QName("", "PUBLICATION-DATE") fn:QName("", "datetime") On Fri, Sep 22, 2017 at 8:15 AM, Christopher Hamlin <cbham...@gmail.com<mailto:cbham...@gmail.com>> wrote: I'm not sure what is the real problem. xs:dateTime ('2003-08-01T08:00:00Z') > xs:dateTime (fn:current-date() - xs:dayTimeDuration("P30D")) , xs:dateTime ('2017-09-28T00:00:00-04:00') > xs:dateTime (fn:current-date() - xs:dayTimeDuration("P30D")) return false and true, no failure. What type is the index, and what is the failure? On Fri, Sep 22, 2017 at 11:10 AM, Geert Josten <geert.jos...@marklogic.com<mailto:geert.jos...@marklogic.com>> wrote: > Hi Kari, > > Looks like you misplaced one of the parentheses. Make sure to wrap the > string "2017-09-22T08:00:00Z” in xs:dateTime(..) before you try to substract > the duration. In provided query you have the xs dateTime cast wrapping both > current-date and the duration. > > Cheers, > Geert > > From: > <general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>> > on behalf of Kari Cowan > <kco...@alm.com<mailto:kco...@alm.com>> > Reply-To: MarkLogic Developer Discussion > <general@developer.marklogic.com<mailto:general@developer.marklogic.com>> > Date: Friday, September 22, 2017 at 4:51 PM > To: MarkLogic Developer Discussion > <general@developer.marklogic.com<mailto:general@developer.marklogic.com>> > Subject: [MarkLogic Dev General] Querying DateTime values > > I need some expert tips on this bug. > > cts:element-attribute-range-query(xs:QName("PUBLICATION-DATE"),xs:QName("datetime"), > ">=", xs:dateTime(fn:current-date() - xs:dayTimeDuration("P30D"))) > > The above query works fine when the publication-date is in this format: > <PUBLICATION-DATE date="2017-09-28" > datetime="2017-09-28T00:00:00-04:00">2017-09-28 > 00:00:00:000</PUBLICATION-DATE> > > But it fails when > <PUBLICATION-DATE date="2003-08-01" > datetime="2003-08-01T08:00:00Z">2003-08-01T08:00:00Z</summary:PUBLICATION-DATE> > > The datetime format is different, but if I manipulate the current-date to > match that format, the query will fail with this message: > > [1.0-ml] XDMP-EXPR: (err:XPTY0004) "2017-09-22T08:00:00Z" - > xs:dayTimeDuration("P30D") -- Invalid expression > > How would I write the query to properly compare the dates? > > The goal above was to return content from the last 30 days. > > > > > > _______________________________________________ > General mailing list > General@developer.marklogic.com<mailto:General@developer.marklogic.com> > Manage your subscription at: > http://developer.marklogic.com/mailman/listinfo/general > _______________________________________________ General mailing list General@developer.marklogic.com<mailto:General@developer.marklogic.com> Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general -- Kari Cowan :: Web Developer :: ALM Media 1035 Market St. Suite 550, San Francisco, CA 94103 iPhone/Text/FaceTime: +1 4157 444 762 -- Kari Cowan :: Web Developer :: ALM Media 1035 Market St. Suite 550, San Francisco, CA 94103 iPhone/Text/FaceTime: +1 4157 444 762
_______________________________________________ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general