简体   繁体   English

ibm的watson-developer-cloud Node.js sdk的Discovery模块中的updateDocument api坚持一个file参数

[英]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.

相关问题 我需要帮助来确定watson-developer-cloud Node.js函数的正确语法,以将文档插入Watson的Discovery服务 - I need help figuring out the correct syntax for the watson-developer-cloud Node.js function to insert a document into Watson's Discovery service 使用Node.js(watson-developer-cloud模块)发送AlchemyData新闻查询 - Sending an AlchemyData News query using Node.js (watson-developer-cloud module) IBM Watson Visual Recognition API,Node.js:未经授权:由于凭证无效,访问被拒绝 - IBM Watson Visual Recognition API, Node.js: Unauthorized: Access is denied due to invalid credentials IBM Bluemix Cloud:用于Node.js的IBM SDK-Bluemix中的应用程序能否保留现有版本而无需自动更新? - IBM Bluemix Cloud: IBM SDK for Node.js - Can our apps in Bluemix keep the existing version without auto-updates? 使用Node.js中的fs模块自动发现脚本 - Automatic script discovery with fs module in Node.js 如何在 node.js 中使用 Watson text-to-speech api? - How to use Watson text-to-speech api in node.js? 文件模块-node.js - file module - node.js 使用Node.js的Winston模块正确记录到文件 - Correct logging to file using Node.js's Winston module function 作为 node.js 模块中的参数 - function as parameter in node.js module 发送到IBM Watson Assistant之前,请在Node.js应用程序中除去上下文变量 - Remove context variable in Node.js app before sending to IBM Watson Assistant
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM