如何在 Marklogic 中使用 Xquery 从数百万条记录中获取 CustomerId

How to get CustomerId from millions of records using Xquery in Marklogic

我们有一个大型数据库,我应该在不影响性能的情况下从整个数据库中只获取 CustomerId。最好的方法是什么?

如果您希望报告大型数据库中的所有 CustomerId 值,那么拥有某种支持索引将是最快和最有效的。使用索引,使用以下函数从词典中检索不同的值列表:

  • cts:values() 例如cts:values(cts:element-reference('CustomerId'))cts:values(cts:path-reference('/Customer/CustomerId'))
  • cts:element-values() 例如cts:element-values(xs:QName("CustomerId"))

您还可以创建一个 TDE that has a CustomerId field and retrieve the values with an Optic 查询。

如果您想在不创建索引的情况下报告这些值,那么您可以创建一个 CoRB 批处理作业来 select 具有该元素的文档,return 来自处理模块,并将值写入输出文件应用 EXPORT-FILE-SORT=ascending|distinct 选项。