ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed t

项目场景:

今天在用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 org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:176)
	at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:2011)
	at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1988)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1745)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1702)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1672)
	at org.elasticsearch.client.RestHighLevelClient.index(RestHighLevelClient.java:1029)
	at com.woniu.EsDemoApplicationTests.insertDoc(EsDemoApplicationTests.java:115)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at 
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
	Suppressed: org.elasticsearch.client.ResponseException: 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 https://www.elastic.co/guide/en/elasticsearch/reference/7.16/security-minimal-setup.html 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 org.elasticsearch.client.RestClient.convertResponse(RestClient.java:326)
		at org.elasticsearch.client.RestClient.performRequest(RestClient.java:296)
		at org.elasticsearch.client.RestClient.performRequest(RestClient.java:270)
		at org.elasticsearch.client.RestHighLevelClient.performClientRequest(RestHighLevelClient.java:2082)
		at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java: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 org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:485)
	at org.elasticsearch.ElasticsearchException.fromXContent(ElasticsearchException.java:396)
	at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:426)
	at org.elasticsearch.ElasticsearchException.failureFromXContent(ElasticsearchException.java:592)
	at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:168)
	... 74 more
Caused by: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=unsupported symbol [.] in geohash [30.871729121.81959]]]
	at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:485)
	at org.elasticsearch.ElasticsearchException.fromXContent(ElasticsearchException.java:396)
	at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java: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}

错误写法:

this.location = hotel.getLatitude()+hotel.getLongitude();

正确写法: 

this.location = hotel.getLatitude()+","+hotel.getLongitude();


解决方案:

字符串拼接前要多检查,并且(纬度,经度)这个顺序不能颠倒,不然可能会导致地理位置错误。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
这个错误是由Elasticsearch引起的,它的类型是mapper_parsing_exception,错误的原因是解析映射时出现问题。具体地,根映射定义中包含不受支持的参数。 下面是一个修复后的映射语句的示例: ``` { "properties": { "birthday": { "type": "date", "store": true }, "hobby": { "type": "text", "store": true }, "id": { "type": "long", "store": true }, "name": { "type": "text", "store": true } } } ``` 请确保你的映射语句与你正在使用的Elasticsearch版本兼容。不同的版本可能会有不同的语法和参数支持。 也请注意,在修复错误之前,确保你的Elasticsearch版本号是正确的。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [properties]](https://blog.csdn.net/ozl544578/article/details/125967168)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [ElasticSearch创建索引报错:mapper_parsing_exception Root mapping definition has unsupported ...](https://blog.csdn.net/sun_luming/article/details/120120533)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小海海不怕困难

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值