Search code examples
pythonelasticsearchelasticsearch-dslelasticsearch-dsl-py

Get @timestamp value in elasticsearch response


I'm using elasticsearch-dsl-py to extract data from elasticsearch.

I want to save the value of the @timestamp field (hits.hits._source.@timestamp). But I have no clue how to deal with the fact that the @ character is not allowed in Python.

How do I get the value from @timestamp? This does not work:

h = response.hits[0]
print(h.@timestamp)

Thanks


Solution

  • In that case you can access that field as follows:

    h = response.hits[0]
    print h['@timestamp']