# \[Maps\] Interpolate line from a set of geopoints & retrieve lastest document with KQL

**URL:** <https://discuss.elastic.co/t/maps-interpolate-line-from-a-set-of-geopoints-retrieve-lastest-document-with-kql/229748>\
**Category:** Kibana\
**Tags:** maps, kql-kibana-query-language\
**Created:** [April 25, 2020, 9:44am UTC](https://discuss.elastic.co/t/maps-interpolate-line-from-a-set-of-geopoints-retrieve-lastest-document-with-kql/229748 "2020-04-25T09:44:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles.w](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charles.w/32/15486_2.png) [@Charles.w](https://discuss.elastic.co/u/Charles.w)\
**Post date:** [April 25, 2020, 9:44am UTC](https://discuss.elastic.co/t/maps-interpolate-line-from-a-set-of-geopoints-retrieve-lastest-document-with-kql/229748/1 "2020-04-25T09:44:26Z")

</div>

Hi,

I'm currently playing with Kibana and FlightRadar, to display all of our "active" flights using the latest version of the stack.

 ![flightradar](https://us1.discourse-cdn.com/elastic/original/3X/3/d/3d89e07f472808070f31a9c391b3f8dc4cb72015.png)

To construct this map, I've been using the following datasets:

- a list of all continents ( [https://datahub.io/core/continent-codes](https://datahub.io/core/continent-codes) )
- a list of all countries ( [https://ourairports.com/data/](https://ourairports.com/data/) )
- a list of all regions ( [https://ourairports.com/data/](https://ourairports.com/data/) )
- a list of all international airports / medium airports / small airports / heliports ( [https://ourairports.com/data/](https://ourairports.com/data/))
- an internal dataset of all of our past/current/future "active" flights
- flightradar APIs to retrieve actual flight data ( [https://www.flightradar24.com/](https://www.flightradar24.com/) )

The map shown above shows the following:

- a geo-line between the departure and the arrival airport
- a clickable bubble on the arrival airport showing relevant informations on the airports
- all airports, depending on zoom level
- the dots of the actual positions at which the plane's ADS-B transmitters pingged
- the latest known position of various planes, oriented using the heading value
- the estimated path between the latest known position of the plane and its arrival airport

All the relevant data for my questions are stored in an index consisting of mostly the following data:

- actual status date time
- geopoint of the ping
- aircraft identification data
- aircraft origin airport stored as a geopoint
- aircraft destination airport stored as a geopoint  
=\> for a single flight, I have as many documents as there are pings

So after this long introduction ( 🙂 ) here's my questions:

- is there a good way to interpolate a line from many geopoints stored within multiple documents in maps ?
- using KQL is there a way to retrieve the document with the highest timestamp while still matching other criteria ? This would be helpful to draw the line between the latest known aircraft position and its destination...so far I'm doing some weird stuff at ingest time.

Best regards,

Charles.w

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [April 26, 2020, 6:04pm UTC](https://discuss.elastic.co/t/maps-interpolate-line-from-a-set-of-geopoints-retrieve-lastest-document-with-kql/229748/2 "2020-04-26T18:04:37Z")

</div>

> is there a good way to interpolate a line from many geopoints stored within multiple documents in maps ?

There is an open enhancement request for a geo\_line aggregation that will convert points into a line. You can follow along at [[Maps][Request]Draw line between geo points on map · Issue #31396 · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues/31396) and [GeoLine Aggregation · Issue #41649 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/41649)

> using KQL is there a way to retrieve the document with the highest timestamp while still matching other criteria ? This would be helpful to draw the line between the latest known aircraft position and its destination...so far I'm doing some weird stuff at ingest time.

You can use [top hits](https://www.elastic.co/guide/en/kibana/7.6/maps-top-hits-aggregation.html) to show the latest position for each aircraft. There is no automated way of showing a line between the current location and destination.

---

<div class="post-metadata">

**Author:** ![Charles.w](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charles.w/32/15486_2.png) [@Charles.w](https://discuss.elastic.co/u/Charles.w)\
**Post date:** [April 28, 2020, 11:33am UTC](https://discuss.elastic.co/t/maps-interpolate-line-from-a-set-of-geopoints-retrieve-lastest-document-with-kql/229748/3 "2020-04-28T11:33:21Z")

</div>

Hi,

Thanks for your answer. Regarding the "current" location of the plane and its destination, both are stored within the same document, but the "top hits" aggregation cannot be used to display geo-line. Thus far, I'm using boolean flags to mark document containing the latest known position, it's not pretty nor elegant but thus far it works...I still need to dig a little more on this 🙂

Best regards,

Charles.w

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [April 28, 2020, 1:36pm UTC](https://discuss.elastic.co/t/maps-interpolate-line-from-a-set-of-geopoints-retrieve-lastest-document-with-kql/229748/4 "2020-04-28T13:36:44Z")

</div>

> Regarding the "current" location of the plane and its destination, both are stored within the same document, but the "top hits" aggregation cannot be used to display geo-line.

You could also index the line in document as a geo\_shape. That way, top hits could just render that stored line. Then you would not need any boolean flags because top hits would only show the most recent document per aircraft

---

<div class="post-metadata">

**Author:** ![Charles.w](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charles.w/32/15486_2.png) [@Charles.w](https://discuss.elastic.co/u/Charles.w)\
**Post date:** [April 28, 2020, 2:03pm UTC](https://discuss.elastic.co/t/maps-interpolate-line-from-a-set-of-geopoints-retrieve-lastest-document-with-kql/229748/5 "2020-04-28T14:03:26Z")

</div>

Good idea, I'll try that tomorrow! Thus far - and as we use ArcGIS for most geo data - I haven't used the elastic stack to display / handle this kind of data. 👍

---

<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:** [May 26, 2020, 2:03pm UTC](https://discuss.elastic.co/t/maps-interpolate-line-from-a-set-of-geopoints-retrieve-lastest-document-with-kql/229748/6 "2020-05-26T14:03:35Z")

</div>

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