将文档上载到CloudSearch,将我的JSON视为字符串
我正在尝试将我的数据文档上载到CloudSearch。我将数据上传到一个名为test.json的文件中,它包含以下内容将文档上载到CloudSearch,将我的JSON视为字符串,json,amazon-web-services,amazon-cloudsearch,Json,Amazon Web Services,Amazon Cloudsearch,我正在尝试将我的数据文档上载到CloudSearch。我将数据上传到一个名为test.json的文件中,它包含以下内容 [ { "type": "add", "id": "1-1", "fields": { "id": 1, "type": 1, "address": "Moeboda 4", "city": "Alvesta",
[
{
"type": "add",
"id": "1-1",
"fields": {
"id": 1,
"type": 1,
"address": "Moeboda 4",
"city": "Alvesta",
"country": "Sweden",
"rooms": 3,
"size": 45,
"price": 275000
}
}
]
我遇到了以下问题:
内容、内容编码、内容类型、资源名称
[ {
"type" : "add",
"id" : "test.json",
"fields" : {
"content" : "[\r\n\t{\r\n\t\t\"type\": \"add\", \r\n\t\t\"id\": \"1-1\", \r\n\t\t\"fields\": {\r\n\t\t\t\"id\": 1,\r\n\t\t\t\"type\": 1,\r\n\t\t\t\"address\": \"Moeboda 4\",\r\n\t\t\t\"city\": \"Alvesta\",\r\n\t\t\t\"country\": \"Sweden\",\r\n\t\t\t\"rooms\": 3,\r\n\t\t\t\"size\": 45,\r\n\t\t\t\"price\": 275000\r\n\t\t}\r\n\t}\r\n]",
"resourcename" : "test.json",
"content_encoding" : "UTF-8",
"content_type" : "application/json"
}
} ]
此问题与.py文件的字符编码有关。当“强制”保存为UTF-8时,它工作了。我想我的编辑已经把它保存为“带BOM的UTF-8”
所以如果你遇到这个问题。Tripple检查您的编码和字符集。如果我在试图上传的json周围加上引号,我会得到相同的行为(它告诉我,我的索引中没有名为“content”、“resourcename”、“content\u encoding”的字段)。我知道您没有在SDF周围显示引号,但是否可能在某处添加了引号?还要确保JSON中没有
null
值。已开始使用Python3进行cloudsearch,并且在编码时不再出现错误。如果编码在您的项目中很重要,我强烈建议您使用python3。另外,请检查您的json文档是否用数组标记包装[]
我的测试是直接的{}
,这就是它失败的原因。