# Get last 10 documents with named field

**URL:** <https://discuss.elastic.co/t/get-last-10-documents-with-named-field/77344>\
**Category:** Elasticsearch\
**Created:** [March 3, 2017, 5:44pm UTC](https://discuss.elastic.co/t/get-last-10-documents-with-named-field/77344 "2017-03-03T17:44:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kryten](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@Kryten](https://discuss.elastic.co/u/Kryten)\
**Post date:** [March 3, 2017, 5:44pm UTC](https://discuss.elastic.co/t/get-last-10-documents-with-named-field/77344/1 "2017-03-03T17:44:11Z")

</div>

Hi,

Would appreciate some assistance.

I need a way to return the last 10 or so documents which contain data in a specified field.  
See sample documents below:

The field I need to retrieve the values from is the "captured\_data" field in the second document.  
Not all my documents will have that field, only some will... I need a way to return, say, the last 10 documents which actually have that field.

Many thanks!

```
{
"_index": "user_data-2017.03.03",
"_type": "logs",
"_id": "AVqVJw5rXDJ0YRPIx7dN",
"_score": 1,
"_source": {
		"message": "action = standard\t[MsgId: MMSG-17999]\r",
    "@version": "1",
    "@timestamp": "2017-03-03T17:10:40.714Z",
    "host": "redpart-667a",
    "path": "04_253.log",
    "handler": "unknown",
    "run": "442",
    "endpoint": "unknown",
    "id": "253",
    "directive": 0,
    "run_type": "not_assigned",
    "last_code": "11751",
    "iteration": "0",
    "site": "fall"
	}
},
{
"_index": "user_data-2017.03.03",
"_type": "logs",
"_id": "AVqVJw5rXDJ0YRPIx7dN",
"_score": 1,
"_source": {
		"message": "action = standard\t[MsgId: MMSG-17999]\r",
    "@version": "1",
    "@timestamp": "2017-03-03T17:10:40.714Z",
    "host": "redpart-667a",
    "path": "04_253.log",
    "handler": "unknown",
    "run": "442",
    "endpoint": "unknown",
    "id": "253",
    "directive": 0,
	"captured_data": "1786tg7812b2",
    "run_type": "not_assigned",
    "last_code": "11751",
    "iteration": "0",
    "site": "fall"
	}
}
```

---

<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:** [March 31, 2017, 5:44pm UTC](https://discuss.elastic.co/t/get-last-10-documents-with-named-field/77344/2 "2017-03-31T17:44:15Z")

</div>

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