简体   繁体   中英

Error while executing a query using elastic search python API

I am not able to execute a query on elastic db using elasticsearch python api. I see the following error. I am getting Ping as True to the elastic object. Can anyone help me with this issue?

es = Elasticsearch(
    ['localhost', 'otherhost'],
    http_auth=(username,pwd),
    port=port_no,
    use_ssl=False
)
>>> es.ping
    True


>>> es.count(index="events-2017.06.09*")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\elasticsearch\client\utils.py", line 73, i
n _wrapped
    return func(*args, params=params, **kwargs)
  File "C:\Python27\lib\site-packages\elasticsearch\client\__init__.py", line 11
23, in count
    doc_type, '_count'), params=params, body=body)
  File "C:\Python27\lib\site-packages\elasticsearch\transport.py", line 312, in
perform_request
    status, headers, data = connection.perform_request(method, url, params, body
, ignore=ignore, timeout=timeout)
  File "C:\Python27\lib\site-packages\elasticsearch\connection\http_urllib3.py",
line 128, in perform_request
    self._raise_error(response.status, raw_data)
  File "C:\Python27\lib\site-packages\elasticsearch\connection\base.py", line 12
5, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_me
ssage, additional_info)
elasticsearch.exceptions.NotFoundError: <exception str() failed>

Did you already try to connect with a web browser or with curl ? Which client tools did you use to connect to ES ?

For example this a client runnung as plugin google chrome: Elastic Search Query Builder

NotFoundError represents 404 , which means ES did not find the resource you requested.

https://elasticsearch-py.readthedocs.io/en/master/exceptions.html

You didn't indicate a port number, so it defaults to port 80. Very often on this port there is a web server installed. And probably your ES runs on a different port eg 9200. And this could explain why you receive a 404 as the web server on 80 does not know about your index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM