2
votes

I do not manage to index GeoJSON data in Elasticsearch and create Tile Map with them.

--> Sending GeoJSON to ES:

curl -XPUT "http://localhost:9200/datas/data/3617" -d 
'{
    "geometry": {
        "coordinates": [
            7.040691666666667,
            43.626736111111114
        ],
        "type": "Point"
    },
    "properties": {
        "createdAt": {
            "$date": "2016-04-06T15:40:42.402Z"
        },
        "device": "000-0002",
        "ind": 0,
        "timestamp": {
            "$date": "2016-04-06T16:40:41.000Z"
        }
    },
    "type": "Feature"
}'

Check mapping

curl -XGET "http://localhost:9200/datas/data/_mapping"

{
  "datas": {
    "mappings": {
      "data": {
        "properties": {
          "geometry": {
            "properties": {
              "coordinates": {
                "type": "float"
              },
              "type": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "properties": {
            "properties": {
              "createdAt": {
                "properties": {
                  "$date": {
                    "type": "date"
                  }
                }
              },
              "device": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "ind": {
                "type": "long"
              },
              "timestamp": {
                "properties": {
                  "$date": {
                    "type": "date"
                  }
                }
              }
            }
          },
          "type": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

But when creating a Tile Map in Kibana, I have the following error in Kibana:

"No Compatible Fields: The "datas" index pattern does not contain any of the following field types: geo_point"

How should I change the mapping so the GeoJSON is usable in the Tile Map ?

EDIT 1

curl -XPUT "http://localhost:9200/datas/_mapping/data" -d '{
    "data": {
       "properties": {
          "geometry": {
             "type": "geo_shape"
          }
       }
    }
  }'

=> {"acknowledged":true}

$ curl -XGET "http://localhost:9200/datas/_mapping/data"

=> {"datas":{"mappings":{"data":{"properties":{"geometry":{"type":"geo_shape"}}}}}}

curl -XPUT "http://localhost:9200/datas/data/3617" -d 
'{
    "geometry": {
        "coordinates": [
            7.040691666666667,
            43.626736111111114
        ],
        "type": "Point"
    },
}'

=> {"_index":"datas","_type":"data","_id":"3617","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}

But when I try to create Tile Map, I have this error message

Tile Map Error

When I replace geo_shape with geo_point in the mapping, I have the following error when inserting a sample data:

curl -XPUT "http://localhost:9200/datas/data/3617" -d 
'{
    "geometry": {
        "coordinates": [
            7.040691666666667,
            43.626736111111114
        ],
        "type": "Point"
    },
}'

{"error":{"root_cause":[{"type":"parse_exception","reason":"field must be either [lat], [lon] or [geohash]"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"parse_exception","reason":"field must be either [lat], [lon] or [geohash]"}},"status":400}
1

1 Answers

3
votes

ES does not ingest GeoJSON directly, instead you need to translate that to the appropriate geo_shape, in your case, it would be a point.

First you need to create an index and a mapping to accept your geo_shape field, like this:

curl -XPUT "http://localhost:9200/datas" -d '{
  "mappings": {
    "data": {
       "properties": {
          "location": {
             "type": "geo_shape"
          }
       }
    }
  }
}'

Then you can index your GeoJSON point like this:

curl -XPUT "http://localhost:9200/datas/data/3617" -d '{
    "location" : {
        "type" : "point",
        "coordinates" : [7.040691666666667, 43.626736111111114]
    }
}'

UPDATE

If you need to only accomodate Geo points, it's easier to use geo_point instead of geo_shape.

curl -XPUT "http://localhost:9200/datas" -d '{
  "mappings": {
    "data": {
       "properties": {
          "location": {
             "type": "geo_point",
             "geohash_prefix": true
          }
       }
    }
  }
}'

curl -XPUT "http://localhost:9200/datas/data/3617" -d '{
    "location" : {
        "lat": 43.626736111111114,
        "lon": 7.040691666666667
    }
}'