简体   繁体   中英

The updateDocument api in the Discovery module of ibm's watson-developer-cloud Node.js sdk insists on a file parameter

I am trying to insert/update documents in IBM's Discovery service via the watson-developer-cloud Node.js SDK, and it's not working. Some of my documents don't have an associated file, so they are metadata-only. This documentation says that You must provide document content, metadata, or both. However, the updateDocument call fails if you try to update a metadata-only document.

I tracked down the problem to line 607 in node-sdk/discovery/v1.js which is requiredParams: ['environment_id', 'collection_id', 'document_id', 'file'] and I believe that is the source of the problem, as it indicates that 'file' is a required parameter, contrary to what the API documentation states. The API documentation must be correct, because I can update a metadata-only document just fine from the Discovery API explorer .

You just need to make sure you call updateJsonDocument() and send an empty object

const DiscoveryV1 = require('watson-developer-cloud/discovery/v1');
const fs = require('fs');

const discovery = new DiscoveryV1({
  username: 'YOUR USERNAME',
  password: 'YOUR PASSWORD',
  version_date: DiscoveryV1.VERSION_DATE_2017_08_01
});

discovery.updateJsonDocument(
  {
    environment_id: 'YOUR ENVIRONMENT ID',
    collection_id: 'YOUR COLLECTION ID',
    configuration_id: 'YOUR CONFIGURATION ID',
    file: {},
    metadata: { foo: 'bar' }
  },
  function(error, data) {
    if (error) {
      console.log(error);
    } else {
      console.log(data);
    }
  }
);

The documentation is not updated but you can see the method here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM