简体   繁体   English

使用python在elasticsearch上批量上传

[英]bulk upload on elasticsearch using python

from elasticsearch import Elasticsearch as ES
import json

json_data[]
with open('00.json', 'r') as f:
    for line in f:
        json_data.append(json.loads(line))

t = '\n'.join(str(item) for item in json_data)

es = ES('127.0.0.1:9200/')
ES_INDEX = 'myindex'
ES_TYPE = 'doc'

es.bulk(ES_INDEX, ES_TYPE, t)

elasticsearch.exception.TransportError: Transport error (406, u'Cone\\tent Header [ ] is not supported') elasticsearch.exception.TransportError:传输错误(406,u'Cone \\ tent Header []不被支持')

There's probably nothing wrong with your code. 您的代码可能没有错。

The problem is it cannot connect to ES. 问题是它无法连接到ES。 I think the problem is resolving localhost, try making it 127.0.0.1:9200. 我认为问题在于解决本地主机,尝试将其设置为127.0.0.1:9200。 If it is a Linux machine then try changing your /etc/hosts file to resolve localhost. 如果是Linux机器,请尝试更改/ etc / hosts文件以解析localhost。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM