[英]How to query AWS CloudSearch domain using Python boto3 library?
I'm trying to use boto3 to query my CloudSearch domain using the docs as a guide: http://boto3.readthedocs.io/en/latest/reference/services/cloudsearchdomain.html#client我正在尝试使用 boto3 以文档为指导查询我的 CloudSearch 域: http ://boto3.readthedocs.io/en/latest/reference/services/cloudsearchdomain.html#client
import boto3
import json
boto3.setup_default_session(profile_name='myprofile')
cloudsearch = boto3.client('cloudsearchdomain')
response = cloudsearch.search(
query="(and name:'foobar')",
queryParser='structured',
returnFields='address',
size=10
)
print( json.dumps(response) )
...but it fails with: ...但它失败了:
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: " https://cloudsearchdomain.eu-west-1.amazonaws.com/2013-01-01/search "
botocore.exceptions.EndpointConnectionError:无法连接到端点 URL:“ https://cloudsearchdomain.eu-west-1.amazonaws.com/2013-01-01/search ”
But how am I supposed to set or configure the endpoint or domain that I want to connect to?但是我应该如何设置或配置我想要连接的端点或域? I tried adding an
endpoint
parameter to the request, thinking maybe it was an accidental omission from the docs, but I got this error response:我尝试向请求添加
endpoint
参数,认为这可能是文档中的一个意外遗漏,但我收到了以下错误响应:
Unknown parameter in input: "endpoint", must be one of: cursor, expr, facet, filterQuery, highlight, partial, query, queryOptions, queryParser, return, size, sort, start, stats
输入中的未知参数:“端点”,必须是以下之一:光标、expr、facet、filterQuery、highlight、partial、query、queryOptions、queryParser、return、size、sort、start、stats
The docs say:文档说:
The endpoint for submitting Search requests is domain-specific.
提交搜索请求的端点是特定于域的。 You submit search requests to a domain's search endpoint.
您向域的搜索端点提交搜索请求。 To get the search endpoint for your domain, use the Amazon CloudSearch configuration service DescribeDomains action.
要获取域的搜索终端节点,请使用 Amazon CloudSearch 配置服务 DescribeDomains 操作。 A domain's endpoints are also displayed on the domain dashboard in the Amazon CloudSearch console.
域的终端节点也会显示在 Amazon CloudSearch 控制台的域控制面板上。
I know what my search endpoint is, but how do I supply it?我知道我的搜索端点是什么,但我如何提供它?
I found a post on a Google forum with the answer.我在 Google 论坛上找到了一个带有答案的帖子。 You have to add the
endpoint_url
parameter into the client constructor eg您必须将
endpoint_url
参数添加到客户端构造函数中,例如
client = boto3.client('cloudsearchdomain', endpoint_url='http://...')
I hope those docs get updated, because I wasted a lot of time before I figured that out.我希望这些文档得到更新,因为我在弄清楚之前浪费了很多时间。
import boto3
client = boto3.client('cloudsearchdomain',
aws_access_key_id= 'access-key',
aws_secret_access_key= 'some-secret-key',
region_name = 'us-east-1', # your chosen region
endpoint_url= 'cloudsearch-url'
# endpoint_url is your Search Endpoint as defined in AWS console
)
response = client.search(
query='Foo', # your search string
size = 10
)
Reference response['hits']
for returned results.返回结果的参考
response['hits']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.