[英]How to query AWS CloudSearch domain using Python boto3 library?
我正在尝试使用 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) )
...但它失败了:
botocore.exceptions.EndpointConnectionError:无法连接到端点 URL:“ https://cloudsearchdomain.eu-west-1.amazonaws.com/2013-01-01/search ”
但是我应该如何设置或配置我想要连接的端点或域? 我尝试向请求添加endpoint
参数,认为这可能是文档中的一个意外遗漏,但我收到了以下错误响应:
输入中的未知参数:“端点”,必须是以下之一:光标、expr、facet、filterQuery、highlight、partial、query、queryOptions、queryParser、return、size、sort、start、stats
文档说:
提交搜索请求的端点是特定于域的。 您向域的搜索端点提交搜索请求。 要获取域的搜索终端节点,请使用 Amazon CloudSearch 配置服务 DescribeDomains 操作。 域的终端节点也会显示在 Amazon CloudSearch 控制台的域控制面板上。
我知道我的搜索端点是什么,但我如何提供它?
我在 Google 论坛上找到了一个带有答案的帖子。 您必须将endpoint_url
参数添加到客户端构造函数中,例如
client = boto3.client('cloudsearchdomain', endpoint_url='http://...')
我希望这些文档得到更新,因为我在弄清楚之前浪费了很多时间。
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
)
返回结果的参考response['hits']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.