Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python amazon cloudsearch无法使用boto添加文档?_Python_Amazon Web Services_Boto_Amazon Cloudsearch - Fatal编程技术网

Python amazon cloudsearch无法使用boto添加文档?

Python amazon cloudsearch无法使用boto添加文档?,python,amazon-web-services,boto,amazon-cloudsearch,Python,Amazon Web Services,Boto,Amazon Cloudsearch,我正在尝试将最新的boto 2.36(?)用于cloudsearch,我使用connect_cloudsearch2建立了连接: user = { 'id': 4, 'username': 'daniella', 'last_activity': 1334253279, 'follower_count': 7, 'location': 'USA', 'snippet': 'Just like D

我正在尝试将最新的boto 2.36(?)用于cloudsearch,我使用connect_cloudsearch2建立了连接:

user =    {
        'id': 4,
        'username': 'daniella',
        'last_activity': 1334253279,
        'follower_count': 7,
        'location': 'USA',
        'snippet': 'Just like Dan, I like to watch a good sunset, but heights scare me.',
    }
doc_service = domain.get_document_service()
for user in users:
   doc_service.add(user['id'], user['last_activity'], user)
   #doc_service.add(user['id'], user) #this does not work either
complete = doc_service.commit()
我得到的错误与doc_service.add在同一行(它直接来自文档):

如果使用注释的“doc_service.add”行而不是其上方的行,则错误为:

boto.cloudsearch2.document.CommitMismatchError: Incorrect number of adds returned. Commit: 1 Response: 0
在这两种情况下都不会添加/提交文档。
云似乎很难使用。。。有人有什么想法吗?

今天我和博托遇到了同样的问题。我试了一段时间,终于找到了解决办法

使用cloudsearch2。我正在使用bot2.38.0

import boto.cloudsearch2
from boto.cloudsearch2.layer2 import Layer2
from boto.cloudsearch2.domain import Domain

# from boto.cloudsearch.domain import Domain
conn = boto.cloudsearch2.connect_to_region("xxxxxx",
                aws_access_key_id='xxxxxxxxxx',
                aws_secret_access_key='xxxxxxxxx')

domain_data =  conn.describe_domains('domaainname')

domain_data = (domain_data['DescribeDomainsResponse']
                          ['DescribeDomainsResult']
                          ['DomainStatusList'])

domain = Domain(conn, domain_data[0])

doc_service = domain.get_document_service()

user =    {
        'id': 4,
        'username': 'daniella',
        'last_activity': 1334253279,
        'follower_count': 7,
        'location': 'USA',
        'snippet': 'Just like Dan, I like to watch a good sunset, but heights scare me.',
    }


doc_service.add(user['id'],  user)
result = doc_service.commit()
print result
让我知道这解决了您的问题吗?

对于“获取搜索”服务,您可以找到我的答案


您找到解决方案了吗?我最初也遇到了同样的问题……我使用cloudsearch2更改了代码,它工作正常!谢谢你的回答!你能投票支持这个答案吗?这样,它会对其他人有帮助,并且可以节省时间。
import boto.cloudsearch2
from boto.cloudsearch2.layer2 import Layer2
from boto.cloudsearch2.domain import Domain

# from boto.cloudsearch.domain import Domain
conn = boto.cloudsearch2.connect_to_region("xxxxxx",
                aws_access_key_id='xxxxxxxxxx',
                aws_secret_access_key='xxxxxxxxx')

domain_data =  conn.describe_domains('domaainname')

domain_data = (domain_data['DescribeDomainsResponse']
                          ['DescribeDomainsResult']
                          ['DomainStatusList'])

domain = Domain(conn, domain_data[0])

doc_service = domain.get_document_service()

user =    {
        'id': 4,
        'username': 'daniella',
        'last_activity': 1334253279,
        'follower_count': 7,
        'location': 'USA',
        'snippet': 'Just like Dan, I like to watch a good sunset, but heights scare me.',
    }


doc_service.add(user['id'],  user)
result = doc_service.commit()
print result