AWS CloudSearch:的值不能是JSON数组或对象

我有一个int-arraytypes的字段有这个问题。 使用aws-sdk作为Node.js,我通过CloudSearchDomain.uploadDocuments()方法提交文档。 文档的JSON(在searchContentvariables中)是在节点进程中创build的,然后我使用:

var params = { contentType: 'application/json', documents: JSON.stringify([searchContent]) }; csd.uploadDocuments(params, function(err, data){ ...(callback process)... }); 

非string的searchContent对象如下所示:

 { id: 1, type: 'Product', hash_type_id: 'Product-1', name: 'Test product', description: 'A test product', category: [ 2 ], content: '<some text here>', state: [ 1 ], hash_all: '<some text>' } 

并像这样串化:

 [{"id":1,"type":"Product","hash_type_id":"Product-1","name":"Test product","description":"A test product","content":" <some text>","category":[2],"state":[1],"hash_all":"<some text>"}] 

我得到的错误是:

 { "message": "{ [\"The value of category cannot be a JSON array or object\"] }", "code": "DocumentServiceException", "time": "2014-11-20T01:24:27.499Z", "statusCode": 400, "retryable": false } 

如前所述,类别字段是int数组types。 为什么我会收到这个消息?

更新:我也尝试使用types数组(Int16Array)的类别字段,具有完全相同的结果。

该文件需要包装在批处理参数中。 在批处理中,每个文档需要具有以下格式:

 { type: "add|update|delete", id: "Unique ID", fields: Document JSON here } 

这需要在一个数组中,即使它只是一个文档。 所以问题中的文档的JSON变成:

 { type: "add", id: "Product-1", fields: { id: 1, type: 'Product', hash_type_id: 'Product-1', name: 'Test product', description: 'A test product', category: [ 2 ], content: '<some text here>', state: [ 1 ], hash_all: '<some text>' } }