这里出的错误是es中常见的geo_shape类型的插入出现:
curl XPOST
{
"mappings": {
"shape": {
"_all": {
"enabled": false
},
"properties": {
"id": {
"type": "keyword"
},
"geometry": {
"type": "geo_shape",
"tree": "geohash",
"strategy": "recursive"
}
}
}
}
}
接下来是一条示例:
{
"id": "f2798da7871844dba2fbb90c1083dda7",
"geometry": {
"type": "polygon",
"coordinates": [
[
[
0.0002769528161925598,
0.0009304545767787741
],
[
0.0002769527669448511,
0.0009304550161516813
],
[
0.0002769533890613468,
0.0009304550383106249
],
[
0.0002769531007758705,
0.0009304583324129131
],
[
0.0002769423377915506,
0.0009304574434056005
],
[
0.0002769432171131423,
0.0009304453496413198
],
[
0.0002769551191177047,
0.000930446170991552
],
[
0.00027695477228457775,
0.0009304514541992943
],
[
0.00027694355159299484,
0.0009304505149532853
],
[
0.00027694336741343435,
0.0009304520513151477
],
[
0.0002769483570040075,
0.0009304525457815098
],
[
0.00027695604579139446,
0.0009304532132122362
],
[
0.00027695595623969686,
0.0009304549064620671
],
[
0.0002769528161925598,
0.0009304545767787741
],
[
0.0002769540439121113,
0.0009304496469345285
],
[
0.0002769541751036308,
0.00093044776834636
],
[
0.00027694379304798403,
0.000930447100484332
],
[
0.0002769436605715204,
0.0009304488617795905
],
[
0.0002769540439121113,
0.0009304496469345285
]
]
]
}
}
{
"error": {
"root_cause": [
{
"type": "parse_exception",
"reason": "invalid LinearRing found (coordinates are not closed)"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse field [geometry] of type [geo_shape]",
"caused_by": {
"type": "parse_exception",
"reason": "invalid LinearRing found (coordinates are not closed)"
}
},
"status": 400
}
请注意这里其实是有解决方案的,具体可以在github上,这里我一并列出来:
11161
在这里重点已经说明了,其实是因为es中由于对建筑物的要求过高,导致面数据插入过程中异常信息,从而得到了我们上面遇到的错误,这里也给出了解决方案,就是这句话:
ignore_malformed
- don’t throw an exception if the data is malformed, but just ignore this field value就是这句话,很重要,这里说明了,只有加入这个字段之后,才能正常插入.
官网里面也给出了相关的解释:
Trying to index the wrong datatype into a field throws an exception by default, and rejects the whole document. The ignore_malformed parameter, if set to true, allows the exception to be ignored. The malformed field is not indexed, but other fields in the document are processed normally.
所以这里其实并不是数据的问题,其实是es中的问题,所以现在我们重新加入之后开始尝试一下:
curl XPOST
{
"mappings": {
"shape": {
"_all": {
"enabled": false
},
"properties": {
"id": {
"type": "keyword"
},
"geometry": {
"type": "geo_shape",
"tree": "geohash",
"strategy": "recursive",
"ignore_malformed": true
}
}
}
}
}
这里再插入一遍,你就会得到如下的结果:
{
"_index": "wkt",
"_type": "shape",
"_id": "_doc",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}