From Kibana devtools to Elasticsearch

Hello everyone.

I am very new to Elasticsearch and Kibana (in fact it is the first time I know the tools), so sorry for noob questions.

I can login to my kibana website (my-company.cloud) using my username and password, and using devtools (Console) I can put a call like:

GET nxxxx-2010.01.*/_search
{
  "query": {
    "match_all": {}
  }
}

And it returns to around 200K results (hits": { "total": 204575,)

Now I want to perform a same search in Python 3

So:

es = Elasticsearch ('my-company.cloud', httpauth=('username', 'password'))

page = es.search(
          
          index = ' nxxxx-2010.01.*',
          
          scroll = '2m',
        
          size = 1000,
          body = {
            "size":10,
            "query": {"match_all": {}}
        })

and I have the error ERROR:root:TransportError(302, '')

How can I transfer the query in Console Kibana to Python code?

Thanks

is mycompany.cloud kibana or elasticsearch? It should be elasticsearch (the 302 is consistent with Kibana's root url).

The query looks fine, I'd try with some light cleanup and being explicit:

es = Elasticsearch([
        'http://username:password@my-company.cloud:9200/'
])

index = also seems to have a leading space on the index name, i'd try removing that

Thanks for that, but now I have the error 404

Here is the full error log:

Traceback (most recent call last):
 File "es.py", line 83, in download_job                                                              "query": {"match_all": {}}
     File "/home/username/anaconda3/lib/python3.6/site-packages/elasticsearch/client/utils.py", line 76, in _wrapped               return func(*args, params=params, **kwargs)                                                                           File "/home/username/anaconda3/lib/python3.6/site-packages/elasticsearch/client/__init__.py", line 655, in search             doc_type, '_search'), params=params, body=body)                                                                       File "/home/username/anaconda3/lib/python3.6/site-packages/elasticsearch/transport.py", line 318, in perform_request          status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout)
                File "/home/username/anaconda3/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 185, in perform_request
                             self._raise_error(response.status, raw_data)                                                                          File "/home/username/anaconda3/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 125, in _raise_error       raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)                 elasticsearch.exceptions.NotFoundError: <unprintable NotFoundError object>
                                                                               During handling of the above exception, another exception occurred:
                                                                                      Traceback (most recent call last):
 File "/home/username/anaconda3/lib/python3.6/logging/__init__.py", line 992, in emit                                          msg = self.format(record)
      File "/home/username/anaconda3/lib/python3.6/logging/__init__.py", line 838, in format                                        return fmt.format(record)
      File "/home/username/anaconda3/lib/python3.6/logging/__init__.py", line 575, in format                                        record.message = record.getMessage()                                                                                  File "/home/username/anaconda3/lib/python3.6/logging/__init__.py", line 336, in getMessage                                    msg = str(self.msg)
            File "/home/username/anaconda3/lib/python3.6/site-packages/elasticsearch/exceptions.py", line 58, in __str__                  cause = ', %r' % self.info['error']['root_cause'][0]['reason']                                                      TypeError: string indices must be integers                                                                              Call stack:
                        File "es.py", line 187, in <module>                                                                 download_job ()
                File "es.py", line 167, in download_job                                                             logging.error(ex)
            Message: NotFoundError(404, 'Not Found', {'statusCode': 404, 'error': 'Not Found', 'message': 'Not Found'})             Arguments: ()    

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.