taraslayshchuk / es2csv

Export from an Elasticsearch into a CSV file
Apache License 2.0
510 stars 191 forks source link

Found 0 results #29

Closed fourteenminusone closed 7 years ago

fourteenminusone commented 7 years ago

I'm trying to use the command line utility es2csv to export data from Elasticsearch into CSV file with the following syntax taken from github repo:

es2csv -i logstash-2015-07-07 -q 'host: localhost' -o database.csv

So in my case I run the following command:

es2csv -i enron_test -q 'http://localhost:9200' -o database.csv

The problem is that this command returns Found 0 results, but I have some documents indexed into Elasticsearch database.

Anyone can solve this problem? Am I wrong in the syntax of the command? Thank you guys

taraslayshchuk commented 7 years ago

Try: es2csv -i enron_test -q '*' -o database.csv

fourteenminusone commented 7 years ago

It gives me this:

`Found 8 results Run query [#################################################################] [8/8] [100%] [0:00:00] [Time: 0:00:00] [828.1 docs/s] Write to csv [####### ] [1/8] [ 12%] [0:00:00] [ETA: 0:00:00] [ 7.2 Kilines/s]Traceback (most recent call last): File "/usr/local/bin/es2csv", line 9, in load_entry_point('es2csv==5.2.1', 'console_scripts', 'es2csv')() File "/usr/local/lib/python3.5/dist-packages/es2csv.py", line 284, in main es.write_to_csv() File "/usr/local/lib/python3.5/dist-packages/es2csv.py", line 237, in write_to_csv line_dict_utf8 = {k: v.encode('utf8') if isinstance(v, unicode) else v for k, v in line_as_dict.items()} File "/usr/local/lib/python3.5/dist-packages/es2csv.py", line 237, in

line_dict_utf8 = {k: v.encode('utf8') if isinstance(v, unicode) else v for k, v in line_as_dict.items()} NameError: name 'unicode' is not defined` On 05/30/2017 03:01 PM, Taras Layshchuk wrote: > > Try: |es2csv -i enron_test -q '*' -o database.csv| > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > , > or mute the thread > . >
taraslayshchuk commented 7 years ago

Please use python 2.7.

fourteenminusone commented 7 years ago

I'm using python 2.7

python Python 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118] on linux2 Type "help", "copyright", "credits" or "license" for more information.

taraslayshchuk commented 7 years ago

File "/usr/local/lib/python3.5/dist-packages/es2csv.py", line 237, in Looks like pip is not.

fourteenminusone commented 7 years ago

How can I use python 2.7 with es2csv?

On May 30, 2017 17:18, "Taras Layshchuk" notifications@github.com wrote:

File "/usr/local/lib/python3.5/dist-packages/es2csv.py", line 237, in

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/taraslayshchuk/es2csv/issues/29#issuecomment-304912153, or mute the thread https://github.com/notifications/unsubscribe-auth/AVe1_Qa1B9zR2biiNcdsD7wZA54M-tk0ks5r_DNUgaJpZM4No_Nv .

fourteenminusone commented 7 years ago

How to uninstall and install again this utility?

taraslayshchuk commented 7 years ago

How can I use python 2.7 with es2csv?

Use pip which using python 2.7 for installation es2csv.

How to uninstall and install again this utility?

pip uninstall es2csv pip install es2csv

matthewbyrne commented 7 years ago

I'm having the same problem, but im using python 2.7:


Run query [                                                              ] [0/1398742] [  0%] [0:00:00] [ETA:  --:--:--] [  0.0 s/docs]Traceback (most recent call last):
  File "/usr/local/bin/es2csv", line 11, in <module>
    load_entry_point('es2csv==5.2.1', 'console_scripts', 'es2csv')()
  File "/Library/Python/2.7/site-packages/es2csv.py", line 283, in main
    es.search_query()
  File "/Library/Python/2.7/site-packages/es2csv.py", line 40, in f_retry
    return f(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/es2csv.py", line 177, in search_query
    res = next_scroll(res['_scroll_id'])
  File "/Library/Python/2.7/site-packages/es2csv.py", line 40, in f_retry
    return f(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/es2csv.py", line 93, in next_scroll
    return self.es_conn.scroll(scroll=self.scroll_time, scroll_id=scroll_id)
  File "/Library/Python/2.7/site-packages/elasticsearch/client/utils.py", line 73, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/Library/Python/2.7/site-packages/elasticsearch/client/__init__.py", line 955, in scroll
    params=params, body=body)
  File "/Library/Python/2.7/site-packages/elasticsearch/transport.py", line 318, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/Library/Python/2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 128, in perform_request
    self._raise_error(response.status, raw_data)
  File "/Library/Python/2.7/site-packages/elasticsearch/connection/base.py", line 122, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError```
taraslayshchuk commented 7 years ago

@matthewbyrne Your request hit 1398742 results. @RicoSpm did you fix your problem?

matthewbyrne commented 7 years ago

@taraslayshchuk Yup. Proud of that. Is there a limit?

taraslayshchuk commented 7 years ago

@matthewbyrne No, please provide more information: OS, python version, es2csv version, elasticsearch version and run arguments. And it will be better to open a separate issue.

matthewbyrne commented 7 years ago

Im running this dockerised ELK stack: https://hub.docker.com/r/sebp/elk/ Using this tag version: ELK: E1L1K4: Elasticsearch 1.7.3, Logstash 1.5.5, and Kibana 4.1.2. OS: Running Enterprise Linux 7 Python version: Python 2.7.6 es2csv version: es2csv 5.2.1 Command: es2csv -f field1 field2 field3 -i logstash-2017.06.19 -q 'type: nginx' -o database.csv>

taraslayshchuk commented 7 years ago

My apologies, but es2csv currently supports only Elasticsearch 2.x and 5.x. You can try to use es2csv-2.4.4 or downgrade to oldest one.

matthewbyrne commented 7 years ago

That looks to have got me over that hurdle. pip install -I es2csv==2.4.4 to install the older version, and the query is running at the moment. Pulling down 5.4million records. Fun.