我正在使用Elasticsearch-py
库连接到正在运行的Elasticsearch实例。我可以在本地运行ES二进制文件,并且Elasticsearch连接到localhost:9200
就好了。但是,当我通过指定运行它的linux机器和端口来覆盖hosts=
kwarg时,在终端中出现以下错误:
2019-08-02 13:13:04,463 (37016) elasticsearch WARNING - PUT
http://host:9200/dev/user/somedataidhere [status:N/A request:2.297s]
Elasticsearch尝试多次执行PUT请求,每次它给我以
结尾的堆栈跟踪self, "Failed to establish a new connection: %s" % e)
NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000000032025860>:
Failed to establish a new connection: [Errno 11001] getaddrinfo failed
它以ConnectionError
结尾,然后我的脚本停止运行:
raise ConnectionError('N/A', str(e), e)
ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x0000000032025860>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed) caused by:
NewConnectionError(<urllib3.connection.HTTPConnection object at 0x0000000032025860>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed)
请注意上述Elasticsearch警告错误如何未在PUT请求中列出主机地址。我在这里的Elasticsearch()
构造函数中指定主机:
esClient = Elasticsearch(hosts={"host": "mycorporatelinuxmachine.company.com", "port": 9200})
按照Elasticsearch类__init__
:
:arg hosts: list of nodes we should connect to. Node should be a
dictionary ({"host": "localhost", "port": 9200}), the entire dictionary
will be passed to the :class:`~elasticsearch.Connection` class as
kwargs, or a string in the format of ``host[:port]`` which will be
translated to a dictionary automatically. If no value is given the
:class:`~elasticsearch.Urllib3HttpConnection` class defaults will be used.
我将主机字典传递给Elasticsearch构造函数的方式似乎没有什么天生的错误。我不太明白为什么会出现这些错误。感谢您能提供的任何帮助。谢谢