我正在尝试使用 Python 将 geojson 文件索引到 elasticsearch(版本 7.6.2)中。这是我在 elasticsearch 中定义的映射。'mappings': { "properties": { "geometry": { "properties": { "coordinates": { "type": "geo_shape" }, "type": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, }}geojson 文件如下所示:{"type": "FeatureCollection","name": "testting","crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },"features": [{ "type": "Feature", "properties": { "LEGEND": "x_1", "THRESHOLD": -109, "COLOR": "0 0 255", "Prediction": "Coverage" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 151.20061069847705, -33.886918725260998 ], [ 151.200620164862698, -33.886467994010133 ].....但是,当我将文件写入 Elasticsearch 时,受到此链接的启发:def geojson2es(gj): for feature in gj['features']: yield featurewith open(input_path+'/'+ data) as f: gj = json.load(f) es = Elasticsearch(hosts=[{'host': 'localhost', 'port': 9200}]) k = [{ "_index": "test", "_source": feature, } for feature in geojson2es(gj)] helpers.bulk(es, k)我有这个错误:{'type': 'mapper_parsing_exception', 'reason': '未能解析 [geo_shape] 类型的字段 [geometry.coordinates]', 'caused_by': {'type': 'parse_exception', 'reason': 'shape must是一个由类型和坐标组成的对象'}}有人遇到过类似的问题吗?我该如何解决?
1 回答
至尊宝的传说
TA贡献1789条经验 获得超10个赞
您的映射不正确。该geo_shape类型已经隐含了typeand coordinates,因此您无需再次声明它们。
所以你的映射应该是这样的,即每个特征都有一个type(例如Feature,一个散列properties和一个geometry类型geo_shape):
{
"mappings": {
"properties": {
"type": {
"type": "keyword"
},
"properties": {
"type": "object"
},
"geometry": {
"type": "geo_shape"
}
}
}
}
添加回答
举报
0/150
提交
取消