Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delimiter option not considered (#51) #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions es2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def next_scroll(scroll_id):
search_args['q'] = query

if '_all' not in self.opts.fields:
search_args['_source_include'] = ','.join(self.opts.fields)
search_args['_source_includes'] = self.opts.fields
self.csv_headers.extend([unicode(field, "utf-8") for field in self.opts.fields if '*' not in field])

if self.opts.debug_mode:
Expand All @@ -124,7 +124,7 @@ def next_scroll(scroll_id):
print('Sorting by: {}.'.format(', '.join(self.opts.sort)))

res = self.es_conn.search(**search_args)
self.num_results = res['hits']['total']
self.num_results = res['hits']['total']['value']

print('Found {} results.'.format(self.num_results))
if self.opts.debug_mode:
Expand Down Expand Up @@ -209,7 +209,7 @@ def write_to_csv(self):
self.num_results = sum(1 for line in codecs.open(self.tmp_file, mode='r', encoding='utf-8'))
if self.num_results > 0:
output_file = codecs.open(self.opts.output_file, mode='a', encoding='utf-8')
csv_writer = csv.DictWriter(output_file, fieldnames=self.csv_headers)
csv_writer = csv.DictWriter(output_file, fieldnames=self.csv_headers, delimiter=unicode(self.opts.delimiter))
csv_writer.writeheader()
timer = 0
widgets = ['Write to csv ',
Expand Down Expand Up @@ -237,3 +237,4 @@ def clean_scroll_ids(self):
self.es_conn.clear_scroll(body=','.join(self.scroll_ids))
except:
pass

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
elasticsearch>=5.5.2,<5.6.0
elasticsearch>= 7.0.1
progressbar2>=3.36.0,<3.37.0
backports.csv>=1.0.5,<1.1.0