在Marklogic中存储XML数据的最佳方式

时间:2012-04-04 20:28:00

标签: marklogic

我是Marklogic世界的新手。我的程序使用自定义Java应用程序每30秒查询一次Further.com获取XML数据源。结果以XML格式返回。 Java应用程序使用XCC API(Marklogic API)将检索到的数据插入到单个XML文件中的ML中。数据大小每分钟6 MB,如果应用程序运行一天左右,数据量将以GB为单位增长。我不知道我需要做任何管理配置才能将大量数据放入MarkLogic中的单个XML文件中。有人可以验证我的方法,或建议我是否必须在管理员级别进行任何配置更改。 XML的结构如下......

<?xml version="1.0" encoding="UTF-8"?>      
<moreovercontentdump>        
<article id="_6232903453">           
<description></description>
<author></author>       
<source_category>Local</source_category>    
<genre>General</genre>  
<publisher></publisher> 
<media_type>text</media_type>   
<docurl>http://www.ilrestodelcarlino.it</docurl>    
<harvest_time>Apr  4 2012  4:28PM</harvest_time>    
<valid_time>May 14 2012  4:27PM</valid_time>    
</article>
<article id="_6232903453">           
<description></description>
<author></author>       
<source_category>Local</source_category>    
<genre>General</genre>  
<publisher></publisher> 
<media_type>text</media_type>   
<docurl>http://www.ilrestodelcarlino.it</docurl>    
<harvest_time>Apr  4 2012  4:28PM</harvest_time>    
<valid_time>May 14 2012  4:27PM</valid_time>    
</article>
<article id="_6232903453">           
<description></description>
<author></author>       
<source_category>Local</source_category>    
<genre>General</genre>  
<publisher></publisher> 
<media_type>text</media_type>   
<docurl>http://www.ilrestodelcarlino.it</docurl>    
<harvest_time>Apr  4 2012  4:28PM</harvest_time>    
<valid_time>May 14 2012  4:27PM</valid_time>    
</article>
</moreovercontentdump>        

2 个答案:

答案 0 :(得分:7)

查看示例XML,我想您可能希望将每篇文章存储在自己的文档中。如果您希望在异步任务中插入每个文档,可以编写FLWOR表达式来调用xdmp:document-insert,或调用xdmp:spawn

最简单的代码可能如下所示:

for $article in xdmp:http-get($some-url, $options)/moreovercontentdump/article
let $uri := concat('moreover/', $article/@id)
return xdmp:document-insert($uri, $article)

您可以通过重写一些原始XML来增强该代码。例如,您可能希望以xs:dateTime格式重新格式化harvest_timevalid_time元素。这样你就可以在这些值上创建一个范围索引。

答案 1 :(得分:2)

一般情况下,如果将来自Further.com的每个响应存储在MarkLogic中作为自己的文档,您将获得更好的服务。在某些方面,在MarkLogic内部,文档就像RDBMS中的行。

另外,如果您插入其中一个30秒,我很难看到每分钟摄取6MB的情况。你遗漏了一些细节吗?