Home > Net >  ElasticSearch _find method to get saved objects returning "not handler found for URI [/s/<sp
ElasticSearch _find method to get saved objects returning "not handler found for URI [/s/<sp

Time:11-10

I am experimenting in Python to retrieve the saved searches in my space in Kibana.

I am trying to follow the example at https://www.elastic.co/guide/en/kibana/current/saved-objects-api-find.html

Here is my code.

    r = requests.get('http://myhost.com:9200/s/guy-levin/api/saved_objects/_find?type=search',
                     auth=(username, password))
    print(r.status_code)
    print(r.text)
    print(r.json())

I get the output:

400
{"error":"no handler found for uri [/s/guy-levin/api/saved_objects/_find?type=search] and method [GET]"}
{'error': 'no handler found for uri [/s/guy-levin/api/saved_objects/_find?type=search] and method [GET]'}

I also tried es.search(), but if I try es.search(doc_type='search') [not even sure if this is right; Internet searches not helpful thus far], I get a stack trace ending with:

elasticsearch.exceptions.AuthorizationException: AuthorizationException(403, 'security_exception', 'action [indices:data/read/search] is unauthorized for user [some_user_name]')

Changing port to 5601, I got this stack trace:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/git/KibanaReader/main.py", line 207, in <module>
    get_saved_search('Blah Blah REST API')
  File "C:/git/KibanaReader/main.py", line 90, in get_saved_search
    r = requests.get('http://kbqa2.nayax.com:5601/s/guy-levin/api/saved_objects/_find?type=search',
  File "C:\git\KibanaReader\venv\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\git\KibanaReader\venv\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\git\KibanaReader\venv\lib\site-packages\requests\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\git\KibanaReader\venv\lib\site-packages\requests\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:\git\KibanaReader\venv\lib\site-packages\requests\adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

CodePudding user response:

The Saved Object API is a Kibana API, so you need to target the Kibana endpoint (port 5601 by default), not the Elasticsearch endpoint (port 9200 by default).

The right URL should be

 http://myhost.com:5601/s/guy-levin/api/saved_objects/_find?type=search
                    ^
                    |
               change this
  • Related