2

Following is my (sample) Elastic search data which has a series of geo coordinates that I'm trying to index.

PUT geomap/_doc/1
{
  "geometry": {
    "coordinates": [
      [
        [
          -10.8544921875,
          49.82380908513249
        ],
        [
          -10.8544921875,
          59.478568831926395
        ],
        [
          2.021484375,
          59.478568831926395
        ],
        [
          2.021484375,
          49.82380908513249
        ],
        [
          -10.8544921875,
          49.82380908513249
        ]
      ]
    ]
  }
}

and this is the elasticsearch mapping I've created for it.

PUT geomap
{
  "mappings": {
    "properties": {
      "geometry": {
        "properties": {
          "coordinates": { "type": "geo_point" }
        }
      }
    }
  }
}

When I tried to insert the data it did not work. I suspect it is due to the fact that I've got arrays of array coordinates. When I updated the sample dataset to single array of coordinates it worked (below).

PUT geomap/_doc/1
{
  "geometry": {
    "coordinates": [
      [
        -10.8544921875,
        49.82380908513249
      ],
      [
        -10.8544921875,
        59.478568831926395
      ],
      [
        2.021484375,
        59.478568831926395
      ],
      [
        2.021484375,
        49.82380908513249
      ],
      [
        -10.8544921875,
        49.82380908513249
      ]
    ]
  }
}

I would be glad to know what mistake I've done in my mapping which doesn't let me to do so.

1 Answer 1

1

I suspect your doc is a polygon so you're gonna want to use geo_shape instead:

PUT geomap
{
  "mappings": {
    "properties": {
      "geometry": {
        "type": "geo_shape",
        "strategy": "recursive"
      }
    }
  }
}

Notice the "recursive" strategy too to support more spatial queries (at least in the newer ES releases).

PUT geomap/_doc/1
{
  "geometry": {
    "coordinates": [
      [
        [
          -10.8544921875,
          49.82380908513249
        ],
        [
          -10.8544921875,
          59.478568831926395
        ],
        [
          2.021484375,
          59.478568831926395
        ],
        [
          2.021484375,
          49.82380908513249
        ],
        [
          -10.8544921875,
          49.82380908513249
        ]
      ]
    ],
    "type": "polygon"
  }
}

Notice how the coords array was wrapped in one more array to comply w/ the geojson standard and that the type: polygon attribute was added.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.