Home > Enterprise >  MarkLogic REST Resources API - patch multiple documents using only one POST request
MarkLogic REST Resources API - patch multiple documents using only one POST request

Time:09-05

I have a question regarding documents patching in MarkLogic databse using REST API.

I have a service written in .NET Core and I use MarkLogic as my store for the data. In my case I must patch thousands of documents and if it is possible, I don't want to make a thousands of requests. To be more specific - I must add a few properties in certain part of JSON document. Following this guides:

I understand, that using PATCH request we can only update one document at a time so I tried to make a POST like this (for now only with one example patch operation)

POST http://host:port/v1/documents HTTP/1.1
Authorization: Basic autorization
Content-Type: multipart/mixed; boundary=BOUNDARY

--BOUNDARY
Content-Type: application/json
Content-Disposition: category=content; attachment; filename=/documents/first_document_to_update.json
X-HTTP-Method-Override: PATCH

{
  "patch": [
    {
      <patch property insert definition>
    }
  ]
}
--BOUNDARY--

but it just created a document with a content from BOUNDARY at uri from Content-Disposition header. I also tried to use X-HTTP-Method-Override header directly on a POST request, it didn't work out either - I got

{
  "errorResponse": {
    "statusCode": 400,
    "status": "Bad Request",
    "messageCode": "REST-REQUIREDPARAM",
    "message": "REST-REQUIREDPARAM: (err:FOER0000) Required parameter: uri"
  }
}

So my conclusion is that it is not possible to make a patch update of multiple documents using one POST request, am I right? Or I am missing something important?

MarkLogic version: 10

CodePudding user response:

Why not make thousands of requests?

If you were do do that in a multi-threaded fashion, you can get a lot more done and don't have to worry about huge transactions either timing out or blowing some limit and erroring out. And you can spread the load across the cluster instead of using just one node to accomplish all of the work.

Even if you figure out how to do multiple in one shot, I would recommend doing it mutli-threaded with many small requests instead, similar to a CoRB job.

  • Related