无法将 GeoJSON 与 Elasticsearch 5 和 Kibana 5 一起使用

Cannot use GeoJSON with Elasticsearch 5 and Kibana 5

我无法在 Elasticsearch 中为 GeoJSON 数据编制索引并使用它们创建 Tile Map。

--> 将 GeoJSON 发送到 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"
}'

检查映射

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

但是在Kibana中创建Tile Map时,我在Kibana中出现如下错误:

"No Compatible Fields: The "datas" 索引模式不包含以下任何字段类型:geo_point"

我应该如何更改映射,以便 GeoJSON 在 Tile 地图中可用?

编辑 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}

但是当我尝试创建 Tile Map 时,出现此错误消息

当我在映射中用 geo_point 替换 geo_shape 时,插入示例数据时出现以下错误:

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}

ES 不会直接提取 GeoJSON,而是您需要将其转换为适当的 geo_shape,在您的情况下,它将是 point.

首先您需要创建一个索引和一个映射来接受您的 geo_shape 字段,如下所示:

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

然后你可以像这样索引你的 GeoJSON 点:

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

更新

如果您只需要容纳地理点,使用 geo_pointgeo_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
    }
}'