项目场景:
今天在用java写代码查ES中数据的时候,出现了下面提示的错误,我排查了一会才发现问题
控制台提示
ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse field [location] of type [geo_point]]
]; nested: ElasticsearchException[Elasticsearch exception [type=parse_exception, reason=unsupported symbol [.] in geohash [30.871729121.81959]]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=unsupported symbol [.] in geohash [30.871729121.81959]]];
at (:176)
at (:2011)
at (:1988)
at (:1745)
at (:1702)
at (:1672)
at (:1029)
at (:115)
at .invoke0(Native Method)
at (:62)
at (:43)
at (:498)
at
at (:53)
at .junit5.(:69)
at $(:33)
at (:230)
at (:58)
Suppressed: : method [PUT], host [http://120.48.46.177:9200], URI [/hotel/_doc/45870?timeout=1m], status line [HTTP/1.1 400 Bad Request]
Warnings: [Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See /guide/en/elasticsearch/reference/7.16/ to enable security.]
{"error":{"root_cause":[{"type":"parse_exception","reason":"unsupported symbol [.] in geohash [30.871729121.81959]"}],"type":"mapper_parsing_exception","reason":"failed to parse field [location] of type [geo_point]","caused_by":{"type":"parse_exception","reason":"unsupported symbol [.] in geohash [30.871729121.81959]","caused_by":{"type":"illegal_argument_exception","reason":"unsupported symbol [.] in geohash [30.871729121.81959]"}}},"status":400}
at (:326)
at (:296)
at (:270)
at (:2082)
at (:1732)
... 71 more
Caused by: ElasticsearchException[Elasticsearch exception [type=parse_exception, reason=unsupported symbol [.] in geohash [30.871729121.81959]]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=unsupported symbol [.] in geohash [30.871729121.81959]]];
at (:485)
at (:396)
at (:426)
at (:592)
at (:168)
... 74 more
Caused by: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=unsupported symbol [.] in geohash [30.871729121.81959]]]
at (:485)
at (:396)
at (:426)
原因分析:
ES中地理坐标属性location的数据结构是(纬度,经度),而我在进行字符串拼接的时候后了中间的逗号,导致插入数据错误。下面就是上面那一段代码真正有用的部分。
真正错误原因:
{"error":{"root_cause":[{"type":"parse_exception","reason":"unsupported symbol [.] in
geohash [30.871729121.81959]"}],"type":"mapper_parsing_exception","reason":"failed to parse
field [location] of type [geo_point]","caused_by":{"type":"parse_exception","reason":"unsupported symbol [.] in geohash
[30.871729121.81959]","caused_by":
{"type":"illegal_argument_exception","reason":"unsupported symbol [.] in geohash
[30.871729121.81959]"}}},"status":400}
错误写法:
= ()+();
正确写法:
= ()+","+();
解决方案:
字符串拼接前要多检查,并且(纬度,经度)这个顺序不能颠倒,不然可能会导致地理位置错误。