gpt4 book ai didi

python - geojson转换为Elasticsearch:无法解析类型为[geo_shape]的字段[geometry.coordinates]

转载 作者:行者123 更新时间:2023-12-03 01:16:51 26 4
gpt4 key购买 nike

我正在尝试使用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时,受到此链接的启发:

How to index geojson file in 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]','
cause_by':
{'type':'parse_exception','reason':'形状必须是由类型和坐标组成的对象'}}


有没有人遇到过类似的问题?我该如何解决?

最佳答案

您的映射不正确。 geo_shape type已经隐含了typecoordinates,因此您无需再次声明它们。

因此,您的映射应该是这样的,即每个功能都有一个type(例如Featureproperties的哈希值和geometry类型的geo_shape):

{
"mappings": {
"properties": {
"type": {
"type": "keyword"
},
"properties": {
"type": "object"
},
"geometry": {
"type": "geo_shape"
}
}
}
}

关于python - geojson转换为Elasticsearch:无法解析类型为[geo_shape]的字段[geometry.coordinates],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62143060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com