1

I am trying to connect and retrieve data from a ES engine.

I am using the following script:

from elasticsearch import Elasticsearch as ES

print "Setup connection..."
es=ES(['http://elasticsearch......com:9200/cuevents-2014.34,cuevents-2014.33/_search?pretty'])
print "Done!"

print "Count number of users..."
print es.count(index='cuevents-2014.34')

But I am getting the following messaged returned instead.

Setup connection...
No handlers could be found for logger "elasticsearch"
Done!
Count number of users...
Traceback (most recent call last):
  File "/home/es.py", line 8, in <module>
    print es.count(index='cuevents-2014.34')
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 68, in _wrapped
    return func(*args, params=params, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 622, in count
    params=params, body=body)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 284, in perform_request
    status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py", line 51, in perform_request
    raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection aborted.', gaierror(-2, 'Name or service not known'))) caused by: ProtocolError(('Connection aborted.', gaierror(-2, 'Name or service not known')))

I am trying to connect and return the number of documents in the index cuevents-2014.34

3
  • Sounds obvious, but are you sure index cuevents-2014.34 exists? Commented Aug 21, 2014 at 1:16
  • Yes I cam sure the index exist. Commented Aug 21, 2014 at 11:18
  • When I use the following i get a response from Marvel- Sense interface. 'code' curl -XGET "elasticsearch....com:9200/cuevents-2014.34,cuevents-2014.33/…" -d' { "size": 0, "aggregations": { "coeunt": { "terms": { "field": "site_name", "size": 0 } } } }''code' Commented Aug 21, 2014 at 11:19

1 Answer 1

2

Okay, I looked at your code again more closely. The Elasticsearch constructor needs to be pointed to the root URL - you're not supposed to specify indexes on the URL.

from elasticsearch import Elasticsearch as ES

print "Setup connection..."
es=ES(['http://elasticsearch......com:9200/'])
print "Done!"

print "Count number of users..."
print es.count(index='cuevents-2014.34')

See http://elasticsearch-py.readthedocs.org/en/master/api.html#elasticsearch

If you want to limit access to only certain indexes - Elasticsearch does not provide access control at all. You can do it via URL rewriting on a reverse proxy.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.