Geo-Line Aggregation

Geo-Line Aggregation

The geo_line aggregation aggregates all geo_point values within a bucket into a LineString ordered by the chosen sort field. This sort can be a date field, for example. The bucket returned is a valid GeoJSON Feature representing the line geometry.

  1. PUT test
  2. {
  3. "mappings": {
  4. "dynamic": "strict",
  5. "_source": {
  6. "enabled": false
  7. },
  8. "properties": {
  9. "my_location": {
  10. "type": "geo_point"
  11. },
  12. "group": {
  13. "type": "keyword"
  14. },
  15. "@timestamp": {
  16. "type": "date"
  17. }
  18. }
  19. }
  20. }
  21. POST /test/_bulk?refresh
  22. {"index": {}}
  23. {"my_location": {"lat":37.3450570, "lon": -122.0499820}, "@timestamp": "2013-09-06T16:00:36"}
  24. {"index": {}}
  25. {"my_location": {"lat": 37.3451320, "lon": -122.0499820}, "@timestamp": "2013-09-06T16:00:37Z"}
  26. {"index": {}}
  27. {"my_location": {"lat": 37.349283, "lon": -122.0505010}, "@timestamp": "2013-09-06T16:00:37Z"}
  28. POST /test/_search?filter_path=aggregations
  29. {
  30. "aggs": {
  31. "line": {
  32. "geo_line": {
  33. "point": {"field": "my_location"},
  34. "sort": {"field": "@timestamp"}
  35. }
  36. }
  37. }
  38. }

Which returns:

  1. {
  2. "aggregations": {
  3. "line": {
  4. "type" : "Feature",
  5. "geometry" : {
  6. "type" : "LineString",
  7. "coordinates" : [
  8. [
  9. -122.049982,
  10. 37.345057
  11. ],
  12. [
  13. -122.050501,
  14. 37.349283
  15. ],
  16. [
  17. -122.049982,
  18. 37.345132
  19. ]
  20. ]
  21. },
  22. "properties" : {
  23. "complete" : true
  24. }
  25. }
  26. }
  27. }

Options

point

(Required)

This option specifies the name of the geo_point field

Example usage configuring my_location as the point field:

  1. "point": {
  2. "field": "my_location"
  3. }

sort

(Required)

This option specifies the name of the numeric field to use as the sort key for ordering the points

Example usage configuring @timestamp as the sort key:

  1. "sort": {
  2. "field": "@timestamp"
  3. }

include_sort

(Optional, boolean, default: false)

This option includes, when true, an additional array of the sort values in the feature properties.

sort_order

(Optional, string, default: "ASC")

This option accepts one of two values: “ASC”, “DESC”.

The line is sorted in ascending order by the sort key when set to “ASC”, and in descending with “DESC”.

size

(Optional, integer, default: 10000)

The maximum length of the line represented in the aggregation. Valid sizes are between one and 10000.