1

我已经编写了将 json 导入到 elasticsearch 的代码,但我的连接错误为'Connection aborted.',error(104, 'Connection reset by peer'

代码是

from pyelasticsearch import ElasticSearch
import sys, json

ES_CLUSTER = 'http://localhost:9200/'
ES_INDEX = 'test'
ES_TYPE = 'doc'
es = ElasticSearch(ES_CLUSTER)

json_docs = []
with open(r'sample_data.json') as open_file:
        data = json.load(open_file)
        for js in data:
                json_docs.append(js)

es.bulk(ES_INDEX, ES_TYPE, json_docs)

错误是

Traceback (most recent call last):
  File "el_ex.py", line 18, in <module>
    es.bulk(ES_INDEX, ES_TYPE, json_docs) 
  File "/home/tradevigil123/.local/lib/python2.7/site-packages/pyelasticsearch/client.py", line 93, in decorate
    return func(*args, query_params=query_params, **kwargs)
  File "/home/tradevigil123/.local/lib/python2.7/site-packages/pyelasticsearch/client.py", line 448, in bulk
    query_params=query_params)
  File "/home/tradevigil123/.local/lib/python2.7/site-packages/pyelasticsearch/client.py", line 281, in send_request
    raise exc.info
urllib3.exceptions.ProtocolError: ('Connection aborted.', error(104, 'Connection reset by peer'))

谁能帮我吗 ?

4

1 回答 1

0

这个错误信息通常意味着对方已经关闭了连接。Elasticsearch 不应该发生这种情况,除非出现垃圾收集或进程死亡等不良问题。你检查过 Elasticsearch 日志吗?之后你可以连接到 Elasticsearch 吗?您的批量请求有多大?您是否尝试过 10MB 之类的批量大小?

于 2017-08-27T17:53:45.927 回答