[英]Search with element-range-query on date field if some of the documents have empty-value elements
我在modificationDateTime
元素上創建了一個元素范圍索引。
我們的xml是這樣的:
<data>
<id>456789</id>
<modificationDateTime>2018-10-15T15:16:37.047Z</modificationDateTime>
<otherElementsFollow> ... </otherElementsFollow>
</data>
我正在使用以下查詢來獲取15th Oct 2018
甚至15日至16日的文檔:
cts:search(/, (
cts:and-query((
cts:directory-query("/my-directory/", "1")
, cts:element-range-query(xs:QName("modificationDateTime"), ">=", xs:dateTime("2018-10-15T00:00:00.000+05:30"))
, cts:element-range-query(xs:QName("modificationDateTime"), "<=", xs:dateTime("2018-10-15T23:59:59.000+05:30"))
))
)
運行查詢時出現以下錯誤:
[1.0-ml] XDMP-CAST: (err:FORG0001) cts:search(fn:collection(), cts:and-query((cts:directory-query("/my-directory/", "1"), cts:element-range-query(xs:QName("modificationDateTime"), ">=", xs:dateTime("2018-10-15T00:00:00+05:30"), (), 1), cts:element-range-query(xs:QName("modificationDateTime"), "<=", xs:dateTime("2018-10-15T23:59:59+05:30"), (), 1)), ())) -- Invalid cast: "" cast as xs:dateTime
經過一些分析,我發現有些XML的<modificationDateTime>
元素值為空,例如:
<data>
<id>1234567</id>
<modificationDateTime></modificationDateTime>
<otherElementsFollow> ... </otherElementsFollow>
</data>
所以這就是導致此問題的原因,我們不能刪除該元素,也不能擁有一些值,因為empty是有效值。
關於如何在空元素上使用范圍索引進行搜索的任何幫助,理想情況下都應考慮這些記錄,但是當我將空值更新為有效的dateTime值時,同一查詢可以正常工作。
如果排除那些具有空元素的文檔是一個選項,則可以將此not-query附加到and-query上,以這樣做:
cts:not-query(
cts:element-value-query(xs:QName("modificationDateTime"), "")
)
HTH!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.