Kibana is unable to display an Array of geo_shape "polygon" data; however, I am able to display a single Polygon geo_shape. I would expect Kibana to parse the Array of results and display each of the polygon objects from within an Array.
Using Elastic Stack 7.16.3 and the DevTools Console, I created an Elasticsearch index with the following:
PUT dat
{
"mappings": {
"properties": {
"polygons": {
"properties": {
"count": {
"type": "integer"
},
"side": {
"type": "text"
},
"location" : {
"type": "geo_shape"
}
}
}
}
}
}
Elasticsearch does not require us to specify whether we are inserting an object or an array of objects; it will handle either. So, I'm able to insert, for example, this Array of Polygon objects and have them recognized as a "geo_shape".
POST /dat/_doc/1
{
"polygons": [
{
"side": "L",
"count": 4,
"location": {
"type": "polygon",
"coordinates": [
[[-10.0, 5.0], [-10.0, 10.0], [-5.0, 10.0], [-5.0, 5.0], [-10.0, 5.0]]
]
}
},
{
"side": "R",
"count": 4,
"location": {
"type": "polygon",
"coordinates": [
[[0.0, 20.0], [0.0, 30.0], [-10.0, 30.0], [-10.0, 20.0], [0.0, 20.0]]
]
}
}
]
}
And I can index a second document into Elasticsearch; this time a single Polygon object (not an array).
POST /dat/_doc/2
{
"polygons":
{
"side": "L",
"count": 4,
"location": {
"type": "polygon",
"coordinates": [
[[-10.0, 5.0], [-10.0, 10.0], [-5.0, 10.0], [-5.0, 5.0], [-10.0, 5.0]]
]
}
}
}
I then created an Index Pattern for dat* in Kibana and try to display the indexed data.
I'm then able to simulate the query that Kibana uses (which I gathered directly from Kibana's Inspector) to show that it is able to retrieve the data stored in Elasticsearch:
GET dat*/_search
{
"docvalue_fields": [],
"size": 10000,
"track_total_hits": 10001,
"_source": [
"polygons.location"
],
"script_fields": {},
"stored_fields": [
"polygons.location"
],
"runtime_mappings": {},
"query": {
"bool": {
"must": [],
"filter": [
{
"bool": {
"must": [
{
"exists": {
"field": "polygons.location"
}
},
{
"geo_bounding_box": {
"polygons.location": {
"top_left": [
-180,
85.05113
],
"bottom_right": [
180,
-66.51326
]
}
}
}
]
}
}
],
"should": [],
"must_not": []
}
}
}
And get the following results:
{
"took" : 695,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "dat",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.0,
"_source" : {
"polygons" : [
{
"location" : {
"coordinates" : [
[
[
-10.0,
5.0
],
[
-10.0,
10.0
],
[
-5.0,
10.0
],
[
-5.0,
5.0
],
[
-10.0,
5.0
]
]
],
"type" : "polygon"
}
},
{
"location" : {
"coordinates" : [
[
[
0.0,
20.0
],
[
0.0,
30.0
],
[
-10.0,
30.0
],
[
-10.0,
20.0
],
[
0.0,
20.0
]
]
],
"type" : "polygon"
}
}
]
}
},
{
"_index" : "dat",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.0,
"_source" : {
"polygons" : {
"location" : {
"coordinates" : [
[
[
-10.0,
5.0
],
[
-10.0,
10.0
],
[
-5.0,
10.0
],
[
-5.0,
5.0
],
[
-10.0,
5.0
]
]
],
"type" : "polygon"
}
}
}
}
]
}
}
When this data is displayed in Kibana, only the single Polygon Object (a simple square) is displayed, but the two Polygon objects in the Polygon Array are NOT displayed.
I would have expected all three polygon/squares to have been displayed in Kibana.
I also verified that the geo_shape field is of the correct type.
GET dat/_field_caps?fields=polygons.location
{
"indices" : [
"dat"
],
"fields" : {
"polygons" : {
"object" : {
"type" : "object",
"metadata_field" : false,
"searchable" : false,
"aggregatable" : false
}
},
"polygons.location" : {
"geo_shape" : {
"type" : "geo_shape",
"metadata_field" : false,
"searchable" : true,
"aggregatable" : true
}
}
}
}
I think an alternative would be for me to flatten the Polygon Array and index individual documents for each polygon. But, I really don't want to do that because the polygon data I have should essentially be one "event" because they are all related to a single instance in time.
Another alternative I considered was to use "multipolygon" geo_shape. But, each Polygon object has additional meta-data attached to it (e.g. count, side) and this information would be lost with "multipolygon". In a separate exercise, I was able to display multiple polygons in Kibana, but doing so loses that additional metadata that is associated with each polygon area because multipolygon doesn't support having additional metadata with each of the coordinate arrays.