[英]How to query AWS CloudSearch domain using Python boto3 library?
[英]How do I connect to an existing CloudSearch domain in boto?
我刚刚开始使用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()
您可以执行conn.list_domains()
,它将返回所有当前域的域对象列表,或者您可以执行conn.lookup('foo')
,它将返回指定域名的Domain对象。
这是完美的解决方案。 我正在使用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)
让我知道任何错误。 我希望这对所有人都有用。
使用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
这对我有用,
我们只有一个域名,
dom =域(con,con.describe_domains()[0])
我最初使用Layer2方法实现了连接:
Layer2(region='region name').lookup('domain name')
。
但是,经过一些分析后,我发现创建连接的延迟非常高。
当我说非常高时,我的意思是创建连接的时间与实际执行查询和获得响应的时间相当(大多数情况下> 500ms)。
因此,我的解决方案是直接创建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'
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.