# Getting the latest entry using Python's requests library

**URL:** <https://discuss.elastic.co/t/getting-the-latest-entry-using-pythons-requests-library/246538>\
**Category:** Elasticsearch\
**Created:** [August 27, 2020, 3:02am UTC](https://discuss.elastic.co/t/getting-the-latest-entry-using-pythons-requests-library/246538 "2020-08-27T03:02:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anowar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anowar/32/74583_2.png) [@Anowar](https://discuss.elastic.co/u/Anowar)\
**Post date:** [August 27, 2020, 3:02am UTC](https://discuss.elastic.co/t/getting-the-latest-entry-using-pythons-requests-library/246538/1 "2020-08-27T03:02:23Z")

</div>

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

```auto
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:

```auto
{"took":0,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":217,"relation":"eq"},"max_score":null,"hits":[{"_index":"sender","_type":"_doc","_id":"id","_score":null,"_source":{"@timestamp":"2020-08-27T02:42:05"},"sort":[1598496125000]}]}}

```

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

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

```

```
print(req.json())

```

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

```auto
{'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]}]}}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 24, 2020, 3:02am UTC](https://discuss.elastic.co/t/getting-the-latest-entry-using-pythons-requests-library/246538/2 "2020-09-24T03:02:35Z")

</div>

Closed on September 24, 2020, 3:02am UTC

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