Skip to content

Commit 1775b74

Browse files
Refactoring, update docs, add --sort arg, fix issue with unicode in field name
1 parent ceaa1e0 commit 1775b74

16 files changed

+546
-320
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ build
55
*.*~
66
.DS_Store
77
*.sublime-*
8+
out.csv

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include docs/HISTORY.rst
2+
include docs/EXAMPLES.rst
3+
include requirements.txt

README.rst

Lines changed: 16 additions & 211 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
======
12
es2csv
23
======
34

@@ -10,6 +11,11 @@ Quick Look Demo
1011
---------------
1112
.. figure:: https://cloud.githubusercontent.com/assets/7491121/12016825/59eb5f82-ad58-11e5-81eb-871a49e39c37.gif
1213

14+
Requirements
15+
------------
16+
| This tool should be used with Elasticsearch 5.x version, for older version please check `2.x release <https://github.com/taraslayshchuk/es2csv/tree/2.x>`_.
17+
| You also need `Python 2.7.x <https://www.python.org/downloads/>`_ and `pip <https://pip.pypa.io/en/stable/installing/>`_.
18+
1319
Installation
1420
------------
1521

@@ -31,26 +37,27 @@ Usage
3137
3238
$ es2csv [-h] -q QUERY [-u URL] [-a AUTH] [-i INDEX [INDEX ...]]
3339
[-D DOC_TYPE [DOC_TYPE ...]] [-t TAGS [TAGS ...]] -o FILE
34-
[-f FIELDS [FIELDS ...]] [-d DELIMITER] [-m INTEGER]
35-
[-s INTEGER] [-k] [-r] [-e] [--verify-certs]
40+
[-f FIELDS [FIELDS ...]] [-S FIELDS [FIELDS ...]] [-d DELIMITER]
41+
[-m INTEGER] [-s INTEGER] [-k] [-r] [-e] [--verify-certs]
3642
[--ca-certs CA_CERTS] [--client-cert CLIENT_CERT]
3743
[--client-key CLIENT_KEY] [-v] [--debug]
3844
3945
Arguments:
4046
-q, --query QUERY Query string in Lucene syntax. [required]
41-
-o, --output_file FILE CSV file location. [required]
47+
-o, --output-file FILE CSV file location. [required]
4248
-u, --url URL Elasticsearch host URL. Default is http://localhost:9200.
4349
-a, --auth Elasticsearch basic authentication in the form of username:password.
4450
-i, --index-prefixes INDEX [INDEX ...] Index name prefix(es). Default is ['logstash-*'].
45-
-D, --doc_types DOC_TYPE [DOC_TYPE ...] Document type(s).
51+
-D, --doc-types DOC_TYPE [DOC_TYPE ...] Document type(s).
4652
-t, --tags TAGS [TAGS ...] Query tags.
4753
-f, --fields FIELDS [FIELDS ...] List of selected fields in output. Default is ['_all'].
54+
-S, --sort FIELDS [FIELDS ...] List of <field>:<direction> pairs to sort on. Default is [].
4855
-d, --delimiter DELIMITER Delimiter to use in CSV file. Default is ",".
4956
-m, --max INTEGER Maximum number of results to return. Default is 0.
50-
-s, --scroll_size INTEGER Scroll size for each batch of results. Default is 100.
51-
-k, --kibana_nested Format nested fields in Kibana style.
52-
-r, --raw_query Switch query format in the Query DSL.
53-
-e, --meta_fields Add meta-fields in output.
57+
-s, --scroll-size INTEGER Scroll size for each batch of results. Default is 100.
58+
-k, --kibana-nested Format nested fields in Kibana style.
59+
-r, --raw-query Switch query format in the Query DSL.
60+
-e, --meta-fields Add meta-fields in output.
5461
--verify-certs Verify SSL certificates. Default is False.
5562
--ca-certs CA_CERTS Location of CA bundle.
5663
--client-cert CLIENT_CERT Location of Client Auth cert.
@@ -59,206 +66,4 @@ Usage
5966
--debug Debug mode on.
6067
-h, --help show this help message and exit
6168
62-
Examples
63-
--------
64-
Searching on localhost and save to database.csv
65-
66-
.. code-block:: bash
67-
68-
$ es2csv -q 'host: localhost' -o database.csv
69-
70-
Same in Query DSL syntax
71-
72-
.. code-block:: bash
73-
74-
$ es2csv -r -q '{"query": {"match": {"host": "localhost"}}}' -o database.csv
75-
76-
Very long queries can be read from file
77-
78-
.. code-block:: bash
79-
80-
$ es2csv -r -q @'~/query string file.json' -o database.csv
81-
82-
With tag
83-
84-
.. code-block:: bash
85-
86-
$ es2csv -t dev -q 'host: localhost' -o database.csv
87-
88-
More tags
89-
90-
.. code-block:: bash
91-
92-
$ es2csv -t dev prod -q 'host: localhost' -o database.csv
93-
94-
On custom Elasticsearch host
95-
96-
.. code-block:: bash
97-
98-
$ es2csv -u my.cool.host.com:9200 -q 'host: localhost' -o database.csv
99-
100-
You are using secure Elasticsearch with nginx? No problem!
101-
102-
.. code-block:: bash
103-
104-
$ es2csv -u http://my.cool.host.com/es/ -q 'host: localhost' -o database.csv
105-
106-
With enabled SSL certificate verification (off by default)
107-
108-
.. code-block:: bash
109-
110-
$ es2csv --verify-certs -u https://my.cool.host.com/es/ -q 'host: localhost' -o database.csv
111-
112-
With your own certificate authority bundle
113-
114-
.. code-block:: bash
115-
116-
$ es2csv --ca-certs '/path/to/your/ca_bundle' --verify-certs -u https://host.com -q '*' -o out.csv
117-
118-
Not default port?
119-
120-
.. code-block:: bash
121-
122-
$ es2csv -u my.cool.host.com:6666/es/ -q 'host: localhost' -o database.csv
123-
124-
With Authorization
125-
126-
.. code-block:: bash
127-
128-
$ es2csv -u http://login:[email protected]:6666/es/ -q 'host: localhost' -o database.csv
129-
130-
With explicit Authorization
131-
132-
.. code-block:: bash
133-
134-
$ es2csv -a login:password -u http://my.cool.host.com:6666/es/ -q 'host: localhost' -o database.csv
135-
136-
Specifying index
137-
138-
.. code-block:: bash
139-
140-
$ es2csv -i logstash-2015-07-07 -q 'host: localhost' -o database.csv
141-
142-
More indexes
143-
144-
.. code-block:: bash
145-
146-
$ es2csv -i logstash-2015-07-07 logstash-2015-08-08 -q 'host: localhost' -o database.csv
147-
148-
Or index mask
149-
150-
.. code-block:: bash
151-
152-
$ es2csv -i logstash-2015-* -q 'host: localhost' -o database.csv
153-
154-
And now together
155-
156-
.. code-block:: bash
157-
158-
$ es2csv -i logstash-2015-01-0* logstash-2015-01-10 -q 'host: localhost' -o database.csv
159-
160-
Collecting all data on all indices
161-
162-
.. code-block:: bash
163-
164-
$ es2csv -i _all -q '*' -o database.csv
165-
166-
Specifying document type
167-
168-
.. code-block:: bash
169-
170-
$ es2csv -D log -i _all -q '*' -o database.csv
171-
172-
Selecting some fields, what you are interesting in, if you don't need all of them (query run faster)
173-
174-
.. code-block:: bash
175-
176-
$ es2csv -f host status date -q 'host: localhost' -o database.csv
177-
178-
Or field mask
179-
180-
.. code-block:: bash
181-
182-
$ es2csv -f 'ho*' 'st*us' '*ate' -q 'host: localhost' -o database.csv
183-
184-
Selecting all fields, by default
185-
186-
.. code-block:: bash
187-
188-
$ es2csv -f _all -q 'host: localhost' -o database.csv
189-
190-
Selecting meta-fields: _id, _index, _score, _type
191-
192-
.. code-block:: bash
193-
194-
$ es2csv -e -f _all -q 'host: localhost' -o database.csv
195-
196-
Selecting nested fields
197-
198-
.. code-block:: bash
199-
200-
$ es2csv -f comments.comment comments.date comments.name -q '*' -i twitter -o database.csv
201-
202-
Max results count
203-
204-
.. code-block:: bash
205-
206-
$ es2csv -m 6283185 -q '*' -i twitter -o database.csv
207-
208-
Retrieve 2000 results in just 2 requests (two scrolls 1000 each):
209-
210-
.. code-block:: bash
211-
212-
$ es2csv -m 2000 -s 1000 -q '*' -i twitter -o database.csv
213-
214-
Changing column delimiter in CSV file, by default ','
215-
216-
.. code-block:: bash
217-
218-
$ es2csv -d ';' -q '*' -i twitter -o database.csv
219-
220-
Changing nested columns output format to Kibana style like
221-
222-
.. code-block:: bash
223-
224-
$ es2csv -k -q '*' -i twitter -o database.csv
225-
226-
An JSON document example
227-
228-
.. code-block:: json
229-
230-
{
231-
"title": "Nest eggs",
232-
"body": "Making your money work...",
233-
"tags": [ "cash", "shares" ],
234-
"comments": [
235-
{
236-
"name": "John Smith",
237-
"comment": "Great article",
238-
"age": 28,
239-
"stars": 4,
240-
"date": "2014-09-01"
241-
},
242-
{
243-
"name": "Alice White",
244-
"comment": "More like this please",
245-
"age": 31,
246-
"stars": 5,
247-
"date": "2014-10-22"
248-
}
249-
]
250-
}
251-
252-
A CSV file in Kibana style format
253-
254-
.. code-block::
255-
256-
body,comments.age,comments.comment,comments.date,comments.name,comments.stars,tags,title
257-
Making your money work...,"28,31","Great article,More like this please","2014-09-01,2014-10-22","John Smith,Alice White","4,5","cash,shares",Nest eggs
258-
259-
A CSV file in default format
260-
261-
.. code-block::
262-
263-
body,comments.0.age,comments.0.comment,comments.0.date,comments.0.name,comments.0.stars,comments.1.age,comments.1.comment,comments.1.date,comments.1.name,comments.1.stars,tags.0,tags.1,title
264-
Making your money work...,28,Great article,2014-09-01,John Smith,4,31,More like this please,2014-10-22,Alice White,5,cash,shares,Nest eggs
69+
[ `Usage Examples <./docs/EXAMPLES.rst>`_ | `Release Changelog <./docs/HISTORY.rst>`_ ]

0 commit comments

Comments
 (0)