es2csv Cheatsheet

967




es2csv is a library written in python which provides command line utility to export documents based on query from elasticsearch to csv.

Installation

pip install git+https://github.com/taraslayshchuk/es2csv.git   #install from git source
pip install es2csv                                             #install using pip

Query and save results to file

es2csv -q 'company: volkswagen' -o cars.csv    #documents matching query string will be saved to cars.csv file

Export required fields

es2csv -f model releaseYear mileage -q 'company: volkswagen' -o cars.csv  #only specified fields like model,releaseYear and mileage will be saved to file

Authorization

es2csv -a username:password -u http://onecompiler:9001/cars/ -q 'company: volkswagen' -o cars.csv

More options with examples

ArgumentsDescriptionDefault ValueExample Command
-u, --urlElasticsearch host urlhttp://localhost:9200es2csv -u http://onecompiler:9001/cars/ -q 'company: volkswagen' -o cars.csv
-i, --index-prefixesIndex name prefixlogstash-*es2csv -i cars -q 'company: volkswagen' -o cars.csv
-t, --tagsQuery tags, can add more than 1 tages2csv -t dev -q 'company: volkswagen' -o cars.csv
-d, --delimiterProvide delimiter to be used in csv file,es2csv -d ':' -q 'company: volkswagen' -o cars.csv
-m, --maxMax results to be written in file0es2csv -m 100 -q 'company: volkswagen' -o cars.csv
-r, --raw-queryCan write query in Query DSL formates2csv -r -q '{"query": {"match": {"company": "volkswagen"}}}' -o cars.csv
--debugSwitches debug mode on
-h, --helpShows help message