Skip to content

Commit a69301e

Browse files
eduardofvtaraslayshchuk
authored andcommitted
Added optional scroll_size argument (#27)
* Added optional scroll_size argument * Some improvement
1 parent 1523c59 commit a69301e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Diff for: README.rst

+12-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ Usage
3131
3232
$ es2csv [-h] -q QUERY [-u URL] [-a AUTH] [-i INDEX [INDEX ...]]
3333
[-D DOC_TYPE [DOC_TYPE ...]] [-t TAGS [TAGS ...]] -o FILE
34-
[-f FIELDS [FIELDS ...]] [-d DELIMITER] [-m INTEGER] [-k]
35-
[-r] [-e] [--verify-certs] [--ca-certs CA_CERTS]
36-
[--client-cert CLIENT_CERT] [--client-key CLIENT_KEY] [-v]
37-
[--debug]
34+
[-f FIELDS [FIELDS ...]] [-d DELIMITER] [-m INTEGER]
35+
[-s INTEGER] [-k] [-r] [-e] [--verify-certs]
36+
[--ca-certs CA_CERTS] [--client-cert CLIENT_CERT]
37+
[--client-key CLIENT_KEY] [-v] [--debug]
3838
3939
Arguments:
4040
-q, --query QUERY Query string in Lucene syntax. [required]
@@ -47,6 +47,7 @@ Usage
4747
-f, --fields FIELDS [FIELDS ...] List of selected fields in output. Default is ['_all'].
4848
-d, --delimiter DELIMITER Delimiter to use in CSV file. Default is ",".
4949
-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.
5051
-k, --kibana_nested Format nested fields in Kibana style.
5152
-r, --raw_query Switch query format in the Query DSL.
5253
-e, --meta_fields Add meta-fields in output.
@@ -204,6 +205,12 @@ Max results count
204205
205206
$ es2csv -m 6283185 -q '*' -i twitter -o database.csv
206207
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+
207214
Changing column delimiter in CSV file, by default ','
208215
209216
.. code-block:: bash
@@ -254,4 +261,4 @@ A CSV file in default format
254261
.. code-block::
255262
256263
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
257-
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
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

Diff for: es2csv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def __init__(self, opts):
6363

6464
self.num_results = 0
6565
self.scroll_ids = []
66-
self.scroll_size = 100
6766
self.scroll_time = '30m'
6867

6968
self.csv_headers = list(META_FIELDS) if self.opts.meta_fields else []
@@ -96,7 +95,7 @@ def next_scroll(scroll_id):
9695
index=','.join(self.opts.index_prefixes),
9796
search_type='scan',
9897
scroll=self.scroll_time,
99-
size=self.scroll_size,
98+
size=self.opts.scroll_size,
10099
terminate_after=self.opts.max_results
101100
)
102101

@@ -264,6 +263,7 @@ def main():
264263
p.add_argument('-f', '--fields', dest='fields', default=['_all'], type=str, nargs='+', help='List of selected fields in output. Default is %(default)s.')
265264
p.add_argument('-d', '--delimiter', dest='delimiter', default=',', type=str, help='Delimiter to use in CSV file. Default is "%(default)s".')
266265
p.add_argument('-m', '--max', dest='max_results', default=0, type=int, metavar='INTEGER', help='Maximum number of results to return. Default is %(default)s.')
266+
p.add_argument('-s', '--scroll_size', dest='scroll_size', default=100, type=int, metavar='INTEGER', help='Scroll size for each batch of results. Default is %(default)s.')
267267
p.add_argument('-k', '--kibana_nested', dest='kibana_nested', action='store_true', help='Format nested fields in Kibana style.')
268268
p.add_argument('-r', '--raw_query', dest='raw_query', action='store_true', help='Switch query format in the Query DSL.')
269269
p.add_argument('-e', '--meta_fields', dest='meta_fields', action='store_true', help='Add meta-fields in output.')

0 commit comments

Comments
 (0)