AWS CloudSearch无法上传文档

时间:2014-08-01 02:02:26

标签: amazon-web-services amazon-cloudsearch

我是AWS和CloudSearch的新手。我写了一个非常简单的应用程序,它将docx文档(已经使用cs-import-document转换为JSON格式)上传到我的搜索域。

代码非常简单:

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"
    }
}]

那么我的做法有什么不对?

谢谢堆!

P.S。我可以手动将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)

2 个答案:

答案 0 :(得分:2)

您的文档ID包含无效字符(句点和冒号)。来自https://aws.amazon.com/articles/8871401284621700

  

在您上传到的所有文档中,ID必须是唯一的   域,可以包含以下字符:a-z(小写   字母),0-9和下划线字符(_)。文件ID必须   以字母或数字开头,最长可达64个字符。

目前还不清楚您发布的端点,但您可能也遇到问题。

答案 1 :(得分:0)

SDK版本2.2.2.0我有完全相同的例外。当我将SDK更新到版本2.2.2.1时,异常消失了。