【问题标题】:Connection error while indexing in Elastic search in aws在 aws 中的弹性搜索中建立索引时出现连接错误
【发布时间】:2018-03-10 09:02:22
【问题描述】:

我想使用来自 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 (Caused by NewConnectionError(': 无法建立新连接: [Errno -2] Name or service not known',))) 引起: ConnectionError(HTTPSConnectionPool(host ='https',端口 = 443):最大重试次数超过 url://search-test-abc-jlpfzhi64qcrhhqxycov5rzgcq.ap-south-1.es.amazonaws.com/:443/test-index/tweet/1(导致by NewConnectionError(': 无法建立新连接: [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)

最后一行出现错误。我还可以完全访问弹性搜索网址。

【问题讨论】:

标签: django python-2.7 amazon-web-services elasticsearch django-haystack


【解决方案1】:

我终于明白了。就我而言,我将主机 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)

【讨论】:

  • 谢谢。我也遇到了同样的问题。
猜你喜欢
  • 2020-08-16
  • 1970-01-01
  • 2015-10-21
  • 2016-09-21
  • 2014-09-01
  • 1970-01-01
  • 2020-01-27
  • 2022-10-23
  • 2020-06-08
相关资源
最近更新 更多