我正在尝试使用 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 feature
with 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是一个由类型和坐标组成的对象'}}
有人遇到过类似的问题吗?我该如何解决?
至尊宝的传说
相关分类