6

我刚刚开始使用 boto 连接到 Amazon CloudSearch。

我让示例正常工作,但我找不到任何连接到现有域的示例,所有示例都创建了一个新域。

四处寻找,我找到了 get_domain,但如果我在连接对象上调用它,它就会失败。

>>> conn.get_domain('foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Layer2' object has no attribute 'get_domain'

关于如何连接到现有域的任何建议?

[编辑] 我从这个开始:http: //boto.cloudhackers.com/en/latest/cloudsearch_tut.html

所以,我所做的一切

import boto
conn = boto.connect_cloudsearch()
4

5 回答 5

10

您可以执行conn.list_domains()此操作将返回所有当前域的域对象列表,也可以执行conn.lookup('foo')此操作将返回指定域名的域对象。

于 2012-10-06T20:33:52.573 回答
7

这是完美的解决方案。 我正在使用 boto 2.38.0

我遇到了其他人面临的同样问题。然后我制作了这个脚本来连接 aws 搜索域并获得结果

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])
search_service = domain.get_search_service()
results = search_service.search(q="abc")

print map(lambda x: x, results)

让我知道任何错误。我希望这对所有人都有效。

于 2015-05-26T06:02:08.347 回答
2

使用 boto 2.36,我通过查看源代码来完成这项工作。

import boto.cloudsearch
# login to AWS
conn = boto.connect_cloudsearch2(region="us-west-1",
                aws_access_key_id='xxxxx',
                aws_secret_access_key='xxxxx')


# get the right Domain:
domain = conn.lookup('toolbox')

print domain
于 2015-03-19T23:48:34.627 回答
0

这对我有用,
我们只有一个域,
dom = Domain(con,con.describe_domains()[0])

于 2013-07-08T14:28:30.903 回答
0

我最初使用 Layer2 方法实现了连接:

Layer2(region='region name').lookup('domain name').

但是,经过一些分析后,我发现创建连接的延迟非常高。

当我说非常高时,我的意思是创建连接的时间与实际执行查询并获得响应的时间相媲美(在大多数情况下 > 500 毫秒)。

因此,我的解决方案是Domain直接创建。注意:这个解决方案很脆弱,但它确实显着减少了延迟

您可以通过执行以下操作来创建域(其中许多值可以通过执行找到aws cloudsearch describe-domains):

        domain = Domain(boto.cloudsearch2.connect_to_region('region name'), {
            'Created': True,
            'Deleted': False,
            'Processing': False,
            'RequiresIndexDocuments': False,
            'DomainId': 'domain_id',
            'DomainName': 'domain_name',
            'SearchInstanceCount': 2,
            'SearchPartitionCount': 1,
            'DocService': {
                'Endpoint': 'doc_service_endpoint',
            },
            'ARN': 'domain_arn',
            'SearchService': {
                'Endpoint': 'search_service_endpoint'
            }
        })
于 2017-06-07T18:10:42.177 回答