# Most recent event for devices

**URL:** <https://discuss.elastic.co/t/most-recent-event-for-devices/119298>\
**Category:** Kibana\
**Created:** [February 9, 2018, 8:39pm UTC](https://discuss.elastic.co/t/most-recent-event-for-devices/119298 "2018-02-09T20:39:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![twojays](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@twojays](https://discuss.elastic.co/u/twojays)\
**Post date:** [February 9, 2018, 8:39pm UTC](https://discuss.elastic.co/t/most-recent-event-for-devices/119298/1 "2018-02-09T20:39:35Z")

</div>

Hi,

I have a fleet of IoT devices that post every couple of minutes their status which could be online or offline. My goal is to have a metric that will show a count of all devices that are currently online, and a count for those that are offline. I want it to be dynamic so that if a device comes online it will drop out of the offline metric and go into the online metric.

My document looks like this:

```
{
"state": {
	"reported": {
		"wifistatus": "online",
		"uuid": "1234-1234-1234-0000"
	}
},
"shadow": {
	"state": {
		"reported": {
			"wifistatus": "online",
			"uuid": "1234-1234-1234-0000",
		}
	},
	"metadata": {
		"reported": {
			"wifistatus": {
				"timestamp": 1518205770
			},
			"uuid": {
				"timestamp": 1518205770
			}
		}
	},
	"version": 231,
	"timestamp": 1518205770
}

```

}

I am using the field "state.reported.wifistatus" to filter devices that are online.

I have been trying to use shadow.timestamp to find the most recent event. (since there could be hundreds of events for a device I need to find only the last event I received)

A problem I am running into is when a device has been offline for more than a year. I can't use a now-1m type of filter. Is there anyway to do this in kibana, if not is there a query in elasticsearch that will help me get this data?

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [February 12, 2018, 1:05pm UTC](https://discuss.elastic.co/t/most-recent-event-for-devices/119298/2 "2018-02-12T13:05:58Z")

</div>

Hey @twojays which version of Kibana are you using? You need the bucket script aggregation in Elasticsearch for this, and the only visualization in Kibana that currently supports this is the [Time Series Visual Builder](https://www.elastic.co/guide/en/kibana/5.4/_featured_visualizations.html) which is available starting in Kibana 5.4

---

<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 12, 2018, 1:06pm UTC](https://discuss.elastic.co/t/most-recent-event-for-devices/119298/3 "2018-03-12T13:06:26Z")

</div>

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