[英]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.我正在尝试通过 watson-developer-cloud Node.js SDK 在 IBM 的 Discovery 服务中插入/更新文档,但它不起作用。 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.
此文档说明You must provide document content, metadata, or both.
However, the updateDocument call fails if you try to update a metadata-only document.但是,如果您尝试更新仅限元数据的文档,则updateDocument调用将失败。
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.我在node-sdk/discovery/v1.js 的第 607 行找到了问题,这是requiredParams: ['environment_id', 'collection_id', 'document_id', 'file']
我相信这是问题的根源,因为它表明 'file' 是一个必需的参数,这与 API 文档的说明相反。 The API documentation must be correct, because I can update a metadata-only document just fine from the Discovery API explorer . API 文档必须是正确的,因为我可以很好地从Discovery API explorer更新仅元数据的文档。
You just need to make sure you call updateJsonDocument()
and send an empty object您只需要确保调用updateJsonDocument()
并发送一个空对象
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 .文档未更新,但您可以在此处查看方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.