Geojson to Elasticsearch : Failed to parse field [geometry.coordinates] of type [geo_shape]

I am trying to indexing geojson file into elasticsearch (version 7.6.2) using Python.

Here is the mapping I defined in elasticsearch.

'mappings': {
  "properties": {
    "geometry": {
      "properties": {
        "coordinates": {
          "type": "geo_shape"
        },
        "type": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    },    
 }
}

This is my geojson file

    {
    "type": "FeatureCollection",
    "name": "testting",
    "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
    "features": [
    { "type": "Feature", "properties": { "LEGEND": "x_1", "THRESHOLD": -109, "COLOR": "0 0 255", "Prediction": "Coverage" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 151.20061069847705, -33.886918725260998 ], [ 151.200620164862698, -33.886467994010133 ].....

However, when I write the file to Elasticsearch, inspired from this link:
How to index geojson file in elasticsearch?

def geojson2es(gj):
    for feature in gj['features']:
        yield feature

with open(input_path+'/'+ data) as f:
    gj = json.load(f)

    es = Elasticsearch(hosts=[{'host': 'localhost', 'port': 9200}])

    k = [{
        "_index": "test",
        "_source": feature,
    } for feature in geojson2es(gj)]

    helpers.bulk(es, k)

I have got this error:

{'type': 'mapper_parsing_exception', 'reason': 'failed to parse field [geometry.coordinates] of type [geo_shape]', ' caused_by': {'type': 'parse_exception', 'reason': 'shape must be an object consisting of type and coordinates'}}

Did anyone encounter a similar issue? How can I fix it?

Would it be possible to share a complete example that can reproduce the issue?

Hi there,
Thanks for following up.
This issue has been fixed by correcting the mappings to:

{
  "mappings": {
    "properties": {
      "type": {
        "type": "keyword"
      },
      "properties": {
        "type": "object"
      },
      "geometry": {
        "type": "geo_shape"
      }
    }
  }
}

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