我想使用 aws 的弹性搜索来满足我的需求。以下代码在我的本地弹性搜索中完全正常,但在尝试连接到 aws elasticsearch 服务时总是出错。我正在使用 python 2.7、django 1.10 和弹性搜索 5.1.1。以下是错误
ConnectionError(HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //search-test-abc-jlpfzhi64qcrhhqxycov5rzgcq.ap-south-1.es.amazonaws.com/:443/test-index/ tweet/1 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f1e2e5e2090>: Failed to build a new connection: [Errno -2] Name or service not known',))) 引起:ConnectionError(HTTPSConnectionPool(host) ='https', port=443): 最大重试次数超过 url: //search-test-abc-jlpfzhi64qcrhhqxycov5rzgcq.ap-south-1.es.amazonaws.com/:443/test-index/tweet/1 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f1e2e5e2090>: 建立新连接失败:[Errno -2] 名称或服务未知',)))另外,这是我正在使用的代码
host = AWS_ELASTIC_SEARCH_URL
awsauth = AWS4Auth(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ELASTIC_SEARCH_REGION, 'es')
es = Elasticsearch(
hosts=[{'host': host, 'port': 443}],
http_auth=awsauth,
use_ssl=True,
verify_certs=True,
connection_class=elasticsearch.RequestsHttpConnection
)
doc = {
'author': 'kimchy',
'text': 'Elasticsearch: cool. bonsai cool.',
'timestamp': datetime.now(),
}
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
它在最后一行给出错误。此外,我已经完全访问了弹性搜索 url。
我终于弄明白了。就我而言,我将主机 url 写为“ https://example.com/ ”,但它应该仅作为“example.com”给出。花了很多时间才把这件事记在我的脑海里。以下是我使用 python 2.7 和 django 1.9 连接到 aws ElasticSearch (5.1) 的工作代码。
def bulk_indexing():
host = 'example.com' #not https://example.com"
awsauth = AWS4Auth('access key', 'secret', region, 'es')
es = Elasticsearch(
hosts=[{'host': host, 'port': 443}],
http_auth=awsauth,
use_ssl=True,
verify_certs=True,
connection_class=RequestsHttpConnection
)
payload = {'abc' : 'def'}
es.index('abc-index', 'doc', payload)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句