Geo_shape mapping for xyz format to xy format

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

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"}}}

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

You have a number of issues including :slight_smile:

  • 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...

1 Like

I can see your polygons are not self-closing, as per GeoJSON polygon spec first and last coordinates pairs need to be identical.

image

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