1

嗨,我正在尝试按照以下方式将文档添加到 cloudsearch 域

http://docs.pythonboto.org/en/latest/cloudsearch_tut.html#adding-documents-to-the-index

我的代码 snppet 是:

import boto
conn = boto.connect_cloudsearch(aws_access_key_id='<>',aws_secret_access_key='<>')
domain = conn.lookup('testfoo')
doc_service = domain.get_document_service()
doc_service.add(doc_id, version, data)

首先,我 在 GAE 上遇到了相同的请求问题 Boto CloudSearch:TypeError: request() got an unexpected keyword argument 'config'

所以我删除了 config kwarg (也不确定后果)然后我得到了

boto.cloudsearch.document.CommitMismatchError: Incorrect number of adds returned. Commit: 1 Response: 0

我的数据是这样的

[
{
        "raw" : "whole bunch of raw text",
        "title" : "My new title",
        "blurb" : "A really exciting article",
        "document_type" : "Tech Guide",
        "url" : "http://www.foobar/7199/tech-advice"
}
]

非常感谢任何帮助

4

2 回答 2

1

事实证明,问题是当我在数据中构建 json 时,它不是 json 而是一个字符串。因此,当这产生发送到 cloudsearch 域的 json 并且它结合了 id 和“添加”操作时,它包括“字段”:“[{“原始”:“整个原始文本”,“标题”:“我的新title", "blurb" : "一篇非常激动人心的文章", "document_type" : "技术指南", "url" : " http://www.foobar/7199/tech-advice " } ]" 作为字符串

解决方案就是数据需要json编码

doc_service.add(doc_id, 版本, json.loads(data) )

于 2013-03-06T12:25:30.247 回答
0

这里只需从数据中删除 []。因为如果你有单个对象,那么你必须用字典传递它。{}

[ { "raw" : "一堆原始文本", "title" : "我的新标题", "blurb" : "一篇非常激动人心的文章", "document_type" : "技术指南", "url" : " http ://www.foobar/7199/tech-advice " } ]

于 2015-05-27T07:32:57.550 回答