首页 文章

在aws中的弹性搜索中进行索引时出现连接错误

提问于
浏览
0

我想使用aws的弹性搜索来实现我的用法 . 以下代码在我的本地弹性搜索中完全正常,但在尝试连接到aws elasticsearch服务时总是会出错 . 我使用的是python 2.7,django 1.10和弹性搜索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('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f1e2e5e2090>: Failed to establish 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(由NewConnectionError引起('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f1e2e5e2090>: Failed to establish a new connection: [Errno -2] Name or service not known',)))
此外,这是我正在使用的代码

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)

它在最后一行给出错误 . 此外,我已完全访问弹性搜索网址 .

1 回答

  • 0

    我终于弄明白了 . 在我的情况下,我只写主机网址为“https://example.com/ ", but it should be given as " 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)
    

相关问题