在 Marklogic DB 中查询以过滤最近 24 小时的文档

Query in Marklogic DB to filter documents for the last 24 hours

有没有办法根据日期字段过滤掉 marklogic 中的文档?

类似于:

select * from data-hub-STAGING where load_date > '2022-01-12'

只要有日期或日期时间被跟踪和索引,就可以发出这样的查询。

对于任何 MarkLogic 数据库,都有一个 database option 来启用“维护上次修改”,这将设置和维护一个文档 属性 prop:last-modified 可以被索引并应用范围查询。

您的示例 table 是“data-hub-STAGING”。如果您使用的是 MarkLogic 数据中心,则 datahubCreatedOn 字段可与 dateTime 范围索引一起使用。

https://docs.marklogic.com/datahub/5.6/flows/about-flows.html#about-flows__pre_ay4_frh_ypb

For every content object outputted by a Data Hub step, regardless of the step type, Data Hub will add the following document metadata keys and values to the document wrapped by the content object:

  • datahubCreatedOn = the date and time at which the document is written

当然,任何其他 date/dateTime 元素、JSON 字段或文档 属性 也可以被索引,然后也可以用于过滤文档。

然后可以将适当的 range query 应用于 JavaScript、XQuery、Optic、SQL 等

中的搜索

例如,在 JavaScript 中按字段 datahubCreatedOn 搜索 cts.fieldRangeQuery():

cts.search(cts.fieldRangeQuery("datahubCreatedOn", ">", 
  new Date(Date.now() - 86400 * 1000).toISOString()))

并在 XQuery 中通过 prop:last-modifiedcts:element-range-query():

进行搜索
cts:search(doc(), cts:element-range-query(xs:QName("prop:last-modified"), ">",
 current-dateTime() + xs:dayTimeDuration("-PT24H")))

如果您要创建一个 SQL Template View.

,您甚至应该能够在您的问题中执行 SQL