2013-03-05 44 views
1

你好我試圖文件添加到cloudsearch域每博託2.8.0和cloudseach

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) 

首先,我得到了同樣的請求事項 Boto CloudSearch on GAE: TypeError: request() got an unexpected keyword argument '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" 
} 
] 

任何幫助,不勝感激

+0

我現在降級請求從1.1.0到0.14.2,看看這會解決什麼,但它確實沒有幫助 – user2135633 2013-03-05 12:39:01

回答

1

原來的問題是,當我在數據建立起來的JSON它不是JSON但一個字符串。所以當這產生被髮送到雲搜索域的json並且它將id和「Add」操作組合時,它包括「字段」:「原始」:「整個原始文本的一堆」, 「標題」: 「我的新頭銜」, 「導語」: 「真正令人興奮的文章」, 「DOCUMENT_TYPE」: 「技術指南」, 「URL」: 「http://www.foobar/7199/tech-advice」 } ]」作爲一個字符串

解決方案簡單地說就是數據需要json編碼

doc_service.add(doc_id,version,json.loads(data)

0

這裏只是從數據中刪除[]。因爲如果你有單個對象,那麼你必須通過詞彙來傳遞它。 {}

[ { 「原始」: 「一大堆原始文本」, 「稱號」: 「我的新頭銜」, 「導語」: 「真正令人興奮的文章」, 「DOCUMENT_TYPE」: 「技術指南」, 「URL」: 「http://www.foobar/7199/tech-advice」 } ]