# Range query on nested object - get latest entry

**URL:** <https://discuss.elastic.co/t/range-query-on-nested-object-get-latest-entry/76705>\
**Category:** Elasticsearch\
**Created:** [February 27, 2017, 11:41pm UTC](https://discuss.elastic.co/t/range-query-on-nested-object-get-latest-entry/76705 "2017-02-27T23:41:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [February 27, 2017, 11:41pm UTC](https://discuss.elastic.co/t/range-query-on-nested-object-get-latest-entry/76705/1 "2017-02-27T23:41:12Z")

</div>

Hi,  
I have the following document:

```
{
	"attributes":[
		{
			"name": "a"
			"effectiveDate": "01-01-2016"
		},{
			"name": "b"
			"effectiveDate": "01-01-2017"
		},{
			"name": "c"
			"effectiveDate": "01-01-2018"
		},{
			"name": "d"
			"effectiveDate": "26-02-2017"
		}
	]
}

```

With the following mappings:

```
"attributes": {
      "type": "nested",
      "properties": {
        "name": {
          "type": "keyword"
        },
        "effectiveDate": {
          "type": "date"
        }
      }
}

```

Is there a way to create a nested range query, so I can get back the closest entry to today.  
let's say today is 28.2.2017, I want to get back:

```
{
    "name": "d"
    "effectiveDate": "26-02-2017"
}

```

Kind of select date\< now() order by date limit 1;

Is this possible?

---

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [March 1, 2017, 11:28am UTC](https://discuss.elastic.co/t/range-query-on-nested-object-get-latest-entry/76705/2 "2017-03-01T11:28:58Z")

</div>

anyone?😑

---

<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 29, 2017, 11:29am UTC](https://discuss.elastic.co/t/range-query-on-nested-object-get-latest-entry/76705/3 "2017-03-29T11:29:06Z")

</div>

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