[英]AWS CloudSearch cannot upload documents
我是AWS和CloudSearch的新手。 我寫了一個非常簡單的應用程序,它將docx文檔(已經使用cs-import-document轉換為JSON格式)上傳到我的seach域。
代碼非常簡單,因為:
using (var searchdomainclient = new AmazonCloudSearchDomainClient("http://search-xxxxx-xysjxyuxjxjxyxj.ap-southeast-2.cloudsearch.amazonaws.com"))
{
// Test to upload doc
var uploaddocrequest = new UploadDocumentsRequest()
{
FilePath = @"c:\temp\testsearch.sdf", //docx to JSON already
ContentType = ContentType.ApplicationJson
};
var uploadresult = searchdomainclient.UploadDocuments(uploaddocrequest);
}
但是,我得到的例外是:“根元素丟失。”
這是我要上傳的sdf文件中的JSON內容:
[{
"type": "add",
"id": "c:_temp_testsearch.docx",
"fields": {
"template": "Normal.dotm",
"application_name": "Microsoft Office Word",
"paragraph_count": "1",
"resourcename": "testsearch.docx",
"date": "2014-07-28T23:52:00Z",
"xmptpg_npages": "1",
"page_count": "1",
"publisher": "",
"creator": "John Smith",
"creation_date": "2014-07-28T23:52:00Z",
"content": "Test5",
"author": "John Smith",
"last_modified": "2014-07-29T04:22:00Z",
"revision_number": "3",
"line_count": "1",
"application_version": "15.0000",
"last_author": "John Smith",
"character_count": "5",
"character_count_with_spaces": "5",
"content_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
}]
那么我的方法有什么問題呢?
謝謝堆!
PS我可以手動將docx doc上傳到該搜索doamin並使用C#代碼應用搜索。
=============更新2014-08-04 ===================
我不確定是否與此相關。 在堆棧跟蹤中,我發現它嘗試解析為XML文件而不是JSON。 但是從我的代碼中,我已經設置了ContentType = JASON,但似乎沒有效果。
at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at Amazon.Runtime.Internal.Transform.XmlUnmarshallerContext.Read()
at Amazon.Runtime.Internal.Transform.ErrorResponseUnmarshaller.Unmarshall(XmlUnmarshallerContext context)
at Amazon.Runtime.Internal.Transform.JsonErrorResponseUnmarshaller.Unmarshall(JsonUnmarshallerContext context)
at Amazon.CloudSearchDomain.Model.Internal.MarshallTransformations.UploadDocumentsResponseUnmarshaller.UnmarshallException(JsonUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
at Amazon.Runtime.Internal.Transform.JsonResponseUnmarshaller.UnmarshallException(UnmarshallerContext input, Exception innerException, HttpStatusCode statusCode)
at Amazon.Runtime.AmazonWebServiceClient.HandleHttpWebErrorResponse(AsyncResult asyncResult, WebException we)
at Amazon.Runtime.AmazonWebServiceClient.getResponseCallback(IAsyncResult result)
at Amazon.Runtime.AmazonWebServiceClient.endOperation[T](IAsyncResult result)
at Amazon.CloudSearchDomain.AmazonCloudSearchDomainClient.EndUploadDocuments(IAsyncResult asyncResult)
at Amazon.CloudSearchDomain.AmazonCloudSearchDomainClient.UploadDocuments(UploadDocumentsRequest request)
at Amazon.CloudSearchDomain.Model.Internal.MarshallTransformations.UploadDocumentsResponseUnmarshaller.UnmarshallException(JsonUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
您的文檔ID包含無效字符(句點和冒號)。 從https://aws.amazon.com/articles/8871401284621700 :
該ID在您上載到域的所有文檔中必須是唯一的,並且可以包含以下字符:az(小寫字母),0-9和下划線字符(_)。 文檔ID必須以字母或數字開頭,最長不能超過64個字符。
還不清楚您要發布到哪個端點,但是那里也可能有問題。
SDK版本2.2.2.0與我完全一樣。 當我將SDK更新到2.2.2.1版時,異常消失了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.