Getting the latest entry using Python's requests library

I tried making a query to get the latest entry of a field by curl:

curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" -d '{"query": {"match_all": {}}, "_source": "@timestamp", "size": 1, "sort": [{"@timestamp": {"order": "desc"}}]}' "http://localhost:9200/sender/_search

With this i was able to get the desired result:


But when i try to the exact thing with Python's "requests" library:

req = requests.get("http://localhost:9200/sender/_search",params={"match":{}, "size": 1,"_source": "@timestamp", "sort": [{"@timestamp": {"order": "desc"}}]})

Instead of getting the latest entry, it returns the very first entry:

{'took': 0, 'timed_out': False, '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 217, 'relation': 'eq'}, 'max_score': None, 'hits': [{'_index': 'sender', '_type': '_doc', '_id': 'different_id', '_score': None, '_source': {'@timestamp': '2020-08-27T02:38:22'}, 'sort': [1598495902000]}]}}

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