# Geo\_shape mapping for xyz format to xy format

**URL:** <https://discuss.elastic.co/t/geo-shape-mapping-for-xyz-format-to-xy-format/273579>\
**Category:** Elasticsearch\
**Created:** [May 20, 2021, 7:10pm UTC](https://discuss.elastic.co/t/geo-shape-mapping-for-xyz-format-to-xy-format/273579 "2021-05-20T19:10:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpavan811](https://avatars.discourse-cdn.com/v4/letter/c/c77e96/32.png) [@cpavan811](https://discuss.elastic.co/u/cpavan811)\
**Post date:** [May 20, 2021, 7:10pm UTC](https://discuss.elastic.co/t/geo-shape-mapping-for-xyz-format-to-xy-format/273579/1 "2021-05-20T19:10:23Z")

</div>

We have field in one of our index with GeoJSON supported format of coordinates [x, y , z] in number format. however when tried to created mapping with geo\_shape format with flag "ignore\_z\_value" to true it still fails to index documents.

Tried other scripting and ingest pipeline methods, but nothing worked out.

I have source document  
'''''''''

{  
"\_index": "test\_index",  
"\_type": "\_doc",  
"\_id": "5f8c01c03f9466001172495b",  
"\_version": 6964426729028846000,  
"\_score": 0,  
"fields": {  
"geometry.type.keyword": [  
"Polygon"  
],  
"type": [  
"Feature"  
],  
"geometry.coordinates": [  
-122.475716,  
37.80737,  
0,  
-122.47572,  
37.80602,  
0,  
-122.47402,  
37.80601,  
0,  
-122.474014,  
37.80736,  
0  
],  
}  
}

''''''''''''

Goal is to get a document like this

'''''''''''

{  
"\_index": "test\_index",  
"\_type": "\_doc",  
"\_id": "5f8c01c03f9466001172495b",  
"\_version": 6964426729028846000,  
"\_score": 0,  
"fields": {  
"geometry.type.keyword": [  
"Polygon"  
],  
"type": [  
"Feature"  
],  
"geometry.coordinates": [  
[  
120.65400,  
24.19446  
],  
[  
-122.47572,  
37.80602,  
],  
[  
-122.47402,  
37.80601,  
],  
[  
-122.474014,  
37.80736,  
],  
}  
}

''''''''''''''''''

Appreciate any help to fix this

---

<div class="post-metadata">

**Author:** ![cpavan811](https://avatars.discourse-cdn.com/v4/letter/c/c77e96/32.png) [@cpavan811](https://discuss.elastic.co/u/cpavan811)\
**Post date:** [May 21, 2021, 2:19am UTC](https://discuss.elastic.co/t/geo-shape-mapping-for-xyz-format-to-xy-format/273579/2 "2021-05-21T02:19:02Z")

</div>

we applied a mapping of

PUT semantics.geofeatures  
{  
"mappings": {  
"properties": {  
"geometry.coordinates": {  
"type": "geo\_shape"  
}  
}  
}  
}

In logs we found below issue

ERROR 2021/05/20 19:25:50 Bulk response item: {"\_index":"semantics.geofeatures","\_type":"\_doc","\_id":"5bd1ab9782104e001f0e089f","status":400,"error":{"type":"mapper\_parsing\_exception","reason":"failed to parse field [geometry.coordinates] of type [geo\_shape]","caused\_by":{"reason":"shape must be an object consisting of type and coordinates","type":"parse\_exception"}}}

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [May 21, 2021, 4:12am UTC](https://discuss.elastic.co/t/geo-shape-mapping-for-xyz-format-to-xy-format/273579/3 "2021-05-21T04:12:51Z")

</div>

Hi @cpavan811 Welcome to the commuinty.

First please format your code going forward using the `</>` button on the editor, it makes it very difficult to understand any many will just skip un-formatted posts.

You probably should take a closer look at the `geo_shape` docs [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html)

You have a number of issues including 🙂

- The Document Structure is not correct
- The Geometry Format is not correct
- Your Polygon Does Not Close, which is required
- The z value will be ignored by default

Here is a working example, hope it helps.

```
DELETE my-geo-index-test
PUT my-geo-index-test
{
  "mappings": {
    "properties": {
      "geometry": {
        "type": "geo_shape"
      }
    }
  }
}

POST my-geo-index-test/_doc
{
  "type": [
    "Feature"
  ],
  "geometry": {
    "type": "polygon",
    "coordinates": [
      [
        [
          -122.475716,
          37.80737,
          0
        ],
        [
          -122.47572,
          37.80602,
          0
        ],
        [
          -122.47402,
          37.80601,
          0
        ],
        [
          -122.474014,
          37.80736,
          0
        ],
        [
          -122.475716,
          37.80737,
          0
        ]
      ]
    ]
  }
}

GET my-geo-index-test/_search
{
  "fields": ["*"]
}

```

Result

```
{
  "took" : 9,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my-geo-index-test",
        "_type" : "_doc",
        "_id" : "i0kcjXkBZ6xyFVkGoAY8",
        "_score" : 1.0,
        "_source" : {
          "type" : [
            "Feature"
          ],
          "geometry" : {
            "type" : "polygon",
            "coordinates" : [
              [
                [
                  -122.475716,
                  37.80737,
                  0
                ],
                [
                  -122.47572,
                  37.80602,
                  0
                ],
                [
                  -122.47402,
                  37.80601,
                  0
                ],
                [
                  -122.474014,
                  37.80736,
                  0
                ],
                [
                  -122.475716,
                  37.80737,
                  0
                ]
              ]
            ]
          }
        },
        "fields" : {
          "type.keyword" : [
            "Feature"
          ],
          "geometry" : [
            {
              "coordinates" : [
                [
                  [
                    -122.475716,
                    37.80737,
                    0.0
                  ],
                  [
                    -122.47572,
                    37.80602,
                    0.0
                  ],
                  [
                    -122.47402,
                    37.80601,
                    0.0
                  ],
                  [
                    -122.474014,
                    37.80736,
                    0.0
                  ],
                  [
                    -122.475716,
                    37.80737,
                    0.0
                  ]
                ]
              ],
              "type" : "Polygon"
            }
          ],
          "type" : [
            "Feature"
          ]
        }
      }
    ]
  }
}

```

I put this on the map...

 ![Screen Shot 2021-05-20 at 9.12.26 PM](https://us1.discourse-cdn.com/elastic/original/3X/b/c/bc266089ef7f130ef682b9ccfb0f36f6914d3a4c.jpeg)

---

<div class="post-metadata">

**Author:** ![jsanz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsanz/32/53734_2.png) [@jsanz](https://discuss.elastic.co/u/jsanz)\
**Post date:** [May 25, 2021, 11:02am UTC](https://discuss.elastic.co/t/geo-shape-mapping-for-xyz-format-to-xy-format/273579/4 "2021-05-25T11:02:27Z")

</div>

I can see your polygons are not self-closing, as per [GeoJSON polygon spec](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.6) first and last coordinates pairs need to be identical.

![image](https://us1.discourse-cdn.com/elastic/original/3X/f/7/f745d2e4ea8f50babc1ff26e7eef910cede6f4b4.png)

---

<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:** [June 22, 2021, 11:02am UTC](https://discuss.elastic.co/t/geo-shape-mapping-for-xyz-format-to-xy-format/273579/5 "2021-06-22T11:02:29Z")

</div>

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