簡體   English   中英

未知的內容類型:json如何在MarkLogic 8中將JSON文檔作為XML加載

[英]Unknown content type: json How to load JSON document as XML in MarkLogic 8

我正在嘗試使用MLCP和攝取時使用的基本轉換腳本將一堆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
  )
};

現在,如果我使用MLCP加載文檔而不進行轉換,則可以正常工作,但是如上所述,我在ML8中獲得了JSON。 (我使用Roxy調用正確的環境以加載到MLCP。)

./ml $ENV mlcp import -input_file_path content/linkedin -input_file_type documents  

以上工作正常。

但是像這樣使用轉換:

./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.MultithreadedMapper:未知內容類型:json”

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)

在查詢控制台中,一切按預期方式工作,將JSON變量按預期方式轉換為XML文檔...

我在這里想念什么?

TX

雨果

根據https://docs.marklogic.com/guide/ingestion/content-pump#id_82518 ,似乎缺少一些障礙。

您沒有指定要存儲的文檔類型(-document_type xml)-您僅存儲xml,而是使用“文檔”作為輸入類型(假設這些是.json擴展名?)-因此代碼不知道該轉換從json轉換為xmls。

您沒有更改URI-因此默認的mime映射將不知道您的輸入和輸出類型期望有所不同:

https://docs.marklogic.com/guide/ingestion/content-pump#id_17589

無論您使用什么后綴,如果沒有提供其他信息,它都無法用於JSON輸入和XML存儲(請參見上面的鏈接)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM