how to add a context name which we give in schema while importing data from a csv file via mlcp

39 views Asked by At

I want to add the context name right now on pushing the data while exploring the document I get is this:-

{{
    "key1": "test1",
    "key2": "test2",
    "key3": "test3",
    "key4": "test4."
}}

where else I want is This:-

{
  "RouterAnomalyData":{
    "key1": "test1",
    "key2": "test2",
    "key3": "test3",
    "key4": "test4."
  }
}

please advise??

1

There are 1 answers

0
Dave Cassel On

I had hoped that the -delimited_root_name option would do what you need, but that only works for XML. I have filed a request on GitHub to add that feature. In the meantime, you'll need to use an MLCP transform. See Transforming Input During Ingestion. Your function will look something like this:

function yourTransform(content, context)
{
  // content.value is a document node. Convert to an object 
  // and wrap it with the new property. 
  const newDoc = {
     "RouterAnomalyData": content.value.toObject()
  }

  // Update the content with the new document. 
  content.value = xdmp.unquote(xdmp.quote(newDoc));

  return content;
}

You can then install the transform and call the transform during ingest. That should result in the structure you're looking for.