我想使用aws的 flex 搜索作为我的用法。以下代码在我的本地 flex 搜索中完全可以正常工作,但是在尝试连接到aws elasticsearch服务时始终会出错。我正在使用python 2.7,django 1.10和 flex 搜索5.1.1。
以下是错误
ConnectionError(HTTPSConnectionPool(host ='https',port = 443):URL超过最大重试次数://search-test-abc-jlpfzhi64qcrhhqxycov5rzgcq.ap-south-1.es.amazonaws.com/:443/test-index/ tweet / 1(由NewConnectionError('
另外,这是我正在使用的代码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)
最后一行给出错误。另外,我已经完全访问了 flex 搜索网址。
最佳答案
我终于弄明白了。就我而言,我将主机网址写为“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)
关于django - 在AWS的Elastic Search中建立索引时出现连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49207274/