如何使用 Python boto3 库查询 AWS CloudSearch 域?
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: Could not connect to the endpoint URL: "https://cloudsearchdomain.eu-west-1.amazonaws.com/2013-01-01/search"
但是我应该如何设置或配置我想要连接的端点或域?我尝试向请求添加一个 endpoint
参数,认为这可能是文档中的意外遗漏,但我得到了这个错误响应:
Unknown parameter in input: "endpoint", must be one of: cursor, expr, facet, filterQuery, highlight, partial, query, queryOptions, queryParser, return, size, sort, start, stats
文档说:
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. A domain's endpoints are also displayed on the domain dashboard in the Amazon CloudSearch console.
我知道我的搜索端点是什么,但我该如何提供它?
我在 Google 论坛上找到了 post 的答案。您必须将 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']
。
我正在尝试使用 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: Could not connect to the endpoint URL: "https://cloudsearchdomain.eu-west-1.amazonaws.com/2013-01-01/search"
但是我应该如何设置或配置我想要连接的端点或域?我尝试向请求添加一个 endpoint
参数,认为这可能是文档中的意外遗漏,但我得到了这个错误响应:
Unknown parameter in input: "endpoint", must be one of: cursor, expr, facet, filterQuery, highlight, partial, query, queryOptions, queryParser, return, size, sort, start, stats
文档说:
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. A domain's endpoints are also displayed on the domain dashboard in the Amazon CloudSearch console.
我知道我的搜索端点是什么,但我该如何提供它?
我在 Google 论坛上找到了 post 的答案。您必须将 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']
。