未知内容类型:json如何在MarkLogic 8中将json文档作为XML加载

未知内容类型:json如何在MarkLogic 8中将json文档作为XML加载,json,xml,marklogic,mlcp,Json,Xml,Marklogic,Mlcp,我正在尝试使用MLCP和ingest上的基本转换脚本将一组JSON文件加载到MarkLogic 8中 我可以按原样加载文件,我可以在ML中获得JSON对象 我想要的是在摄取时将JSON转换为XML,因此我编写了一个基本转换,如下所示: xquery version "1.0-ml"; module namespace ingest = "http://dikw.com/ingest/linkedin"; import module namespace json="http://marklog

我正在尝试使用MLCP和ingest上的基本转换脚本将一组JSON文件加载到MarkLogic 8中

我可以按原样加载文件,我可以在ML中获得JSON对象

我想要的是在摄取时将JSON转换为XML,因此我编写了一个基本转换,如下所示:

xquery version "1.0-ml";

module namespace ingest = "http://dikw.com/ingest/linkedin";

import module namespace json="http://marklogic.com/xdmp/json" at "/MarkLogic/json/json.xqy";
import module namespace sem="http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";

declare namespace basic="http://marklogic.com/xdmp/json/basic";

declare default function namespace "http://www.w3.org/2005/xpath-functions";

declare option xdmp:mapping "false";

declare function ingest:transform(
  $content as map:map,
  $context as map:map
) as map:map*
{
  let $org-doc := map:get($content, "value")
  let $jsonxml := json:transform-from-json($org-doc)
  let $name := $jsonxml//basic:full__name
  let $_ := xdmp:log(concat('Inserting linkedin profile ', $name, '.xml..'))
  let $new-doc := 
    document {
      <json>{
        $jsonxml
      }</json>
  }
  return (
    map:put($content, "value", $new-doc),
    $content
  )
};
以上工作正常

但是使用这样的变换:

./ml $ENV mlcp import -input_file_path content/linkedin -input_file_type documents  -transform_module /ingest/linkedin.xqy -output_collections incoming,incoming/linkedin
我收到一个错误:“error contentpump.multi-threadedmapper:Unknown content type:json”

在查询控制台中,事情按预期进行,将JSON变量按预期转换为XML文档

我错过了什么

德克萨斯州

雨果似乎少了一些东西

您没有指定要存储的文档类型(-document_type xml)-您只存储xml,而是使用“documents”作为输入类型(假设这些是.json扩展名?)-因此代码不知道转换正在从json转换为xmls

您没有更改URI-因此默认mime映射不会知道您的输入和输出类型预期会有所不同:


无论您使用什么后缀,如果没有提供额外信息(请参见上面的链接),它都无法用于JSON输入和XML存储。

事实上,在添加-document\u type XML-transform\u名称空间时,它可以工作。。。有点棘手,您必须在mlcp中指定在transform.xqy中要执行的操作。。。除了下面的答案之外:你在使用最新的MLCP吗?@grtjn:我在github上从最新的roxy运行它。/ml hugo MLCP-v java-cp”/usr/local/MLCP/lib/hadoop-auth-2.0.0-alpha.jar…这里有很多东西…”com.marklogic.contentpump.contentpumpi如果你不记得自己在/usr/local/MLCP/下安装的是哪个版本的MLCP,然后我们可以从xcc jar版本中推断出这一点。它是用-v显示的吗?
./ml $ENV mlcp import -input_file_path content/linkedin -input_file_type documents  -transform_module /ingest/linkedin.xqy -output_collections incoming,incoming/linkedin
15/06/22 17:37:12 INFO contentpump.ContentPump: Hadoop library version: 2.0.0-mr1-cdh4.3.0
15/06/22 17:37:12 INFO contentpump.LocalJobRunner: Content type is set to MIXED.  The format of the  inserted documents will be determined by the MIME  type specification configured on MarkLogic Server.
15/06/22 17:37:12 WARN util.KerberosName: Kerberos krb5 configuration not found, setting default realm to empty
15/06/22 17:37:12 INFO input.FileInputFormat: Total input paths to process : 9
15/06/22 17:37:13 ERROR contentpump.MultithreadedMapper: Unknown content type: json
java.lang.IllegalArgumentException: Unknown content type: json
    at com.marklogic.mapreduce.ContentType.forName(ContentType.java:107)
    at com.marklogic.contentpump.utilities.TransformHelper.getTransformInsertQry(TransformHelper.java:124)
    at com.marklogic.contentpump.TransformWriter.write(TransformWriter.java:97)
    at com.marklogic.contentpump.TransformWriter.write(TransformWriter.java:46)
    at org.apache.hadoop.mapreduce.task.TaskInputOutputContextImpl.write(TaskInputOutputContextImpl.java:85)
    at org.apache.hadoop.mapreduce.lib.map.WrappedMapper$Context.write(WrappedMapper.java:106)
    at com.marklogic.contentpump.DocumentMapper.map(DocumentMapper.java:46)
    at com.marklogic.contentpump.DocumentMapper.map(DocumentMapper.java:32)
    at com.marklogic.contentpump.BaseMapper.runThreadSafe(BaseMapper.java:51)
    at com.marklogic.contentpump.MultithreadedMapper$MapRunner.run(MultithreadedMapper.java:376)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)