es批量导出数据到csv

1、pip install es2csv

2、修改两处源码 

  sudo vim /usr/local/lib/python2.7/dist-packages/es2csv.py

   修改127 行 为了和ES 新版本 兼容

 self.num_results = res['hits']['total']['value'] 

    第212行  为了使得分隔符生效

csv_writer = csv.DictWriter(output_file, fieldnames=self.csv_headers, delimiter=unicode(self.opts.delimiter))

3、操作命令

 es2csv -d '|' -i online-iteach-front-client-log-2021 -q '{"_source": {"includes": ["app_sessionId", "log_type", "software_version", "log_time", "app_id", "app_key","app_type", "device_id", "platform", "url", "text", "event_type", "exit_code","termination_status", "r_time"]},"query": {"bool": {"filter": [{"range": {"r_time": {"gte": "2021-08-01 00:00:00","lte": "2021-08-01 23:59:59"}}}],"must": [{"match_phrase": {"event_type": "web_crash"}}]}}}' -r -o ping_log.csv -u 172.26.5.113:9200  -s 10000 

你可能感兴趣的:(个人日记,elasticsearch)