从文档中获取有限元素

时间:2017-01-17 12:47:01

标签: marklogic marklogic-8

我有像 -

这样的文件
<a:root xmlns:a = 'some-ns'>
    <a:id>some-id</a:id>
    .
    .
    <a:number field='field1'>3</a:number>
    <a:number field='field2'>4</a:number>
    .
    .
</a:root>

我确实要获取要提取的文档的ID,我想要提取与查询匹配的所有文档的a:ida:number,而不使用XPath 。 我可以使用cts.elementValueQuery轻松获取与id匹配的文档,然后使用XPath获取元素。像这样的东西 -

cts.search(  
  cts.andQuery(
    [
      cts.collectionQuery('liveCollection'),
      cts.elementValueQuery(fn.QName(a, 'id'), 'http://iddn.icis.com/series/energy/cegh-day-ahead-index')      
    ]
  )
).next().value.getElementsByTagNameNS(a, 'number')

但我希望MarkLogic只返回选定的元素。

有谁能告诉我这样做的最佳方法?

我写了这个查询(没有给我预期的结果) -

cts.elementValueCoOccurrences(
  fn.QName(c, 'id'), 
  fn.QName(c, 'precision'), 
  ('map'),
  cts.andQuery(
      [
        cts.collectionQuery(liveCollection),
        cts.elementValueQuery(fn.QName(c, 'id'), seriesIds)
      ]
    )
  )

我希望得到这样的输出 -

| <a:id>id-1</a:id> | <a:number field='field1'>3</a:number> |

| <a:id>id-1</a:id> | <a:number field='field2'>4</a:number> |

| <a:id>id-2</a:id> | <a:number field='field1'>3</a:number> |

1 个答案:

答案 0 :(得分:3)

这在某些方面是一个数据建模挑战。您不希望过滤文档(xPath到它们),但您只想要部分结果。

即使您尝试使用可搜索的表达式,但默认结果是第一次匹配,因此您仍需要启用已过滤的查询。

不幸的是,优化的方法是通过范围索引...但是一旦索引到位,您就可以使用共生来提取json结果集中的id和数字,然后进一步处理。

相关问题