Create Elastic index from Python script


I am trying to create an index in ES 7.9.1 with python 3. In order to do so I am using elasticsearch python package.


      doc = {
        'response_time': measure_response_time(app_url, request_timeout),
      index_name='java-response-time-'+str('%Y-%m-%d'))'index: '+index_name)
      res = es.index(index=index_name,id=doc_id, body=doc)'Estado nuevo indice: '+str(res['result']))
      res = es.get(index=index_name, id=doc_id)"Tiempo de respuesta: "+ str(res['_source']['response_time']))

When I specify @timestamp as a time field:

Documents are missing in "Discover" page:

Reminder: This only happens when I select the field @timestamp as a date time field. If I don't select it, then documents appear.

What is the correct date time format that I must use in my python script?

Thanks in advance!

Hi !
It's just an idea but do you have same UTC zone on your python client / elasticsearch server ? (Maybe you can find out by looking at the indexed doc with no @timestamp specified)
Not sure that Elasticsearch will index data happening in the future.
You can (should) add the UTC info in (default default parameter tz=None)


Your comment shed some light on the matter and I managed to make the script work!

Eventually, what made it work was the following code:

      local_tz = pytz.timezone('Europe/Madrid')
      dt = local_tz.localize(
      doc = {
        'response_time': measure_response_time(app_url, request_timeout),
        '@timestamp': dt,
        'time':"%Y-%m-%d %H:%M")

Comment, I set the Kibana timezone in Advaced Settings to: "Europe/Madrid". By default it takes the one from the web navigator,
Thank you @abrx!

1 Like

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