简体   繁体   English

Java RestHighLevelClient - 弹性搜索 - 如何在 id 字段值中添加特殊字符“/”

[英]Java RestHighLevelClient - Elastic Search - How to add special character '/' in id field value

Getting exception while inserting field value with '/' in elastic search在弹性搜索中使用“/”插入字段值时出现异常

Code:代码:

String id = "/EACVBSDSFASFA";

IndexRequest indexRequest = new IndexRequest(INDEX, TYPE, id).source(objectsMap);
                    IndexResponse indexResponse = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);

Exception:例外:

Path part [/EACVBSDSFASFA] couldn't be encoded: java.lang.IllegalArgumentException
java.lang.IllegalArgumentException: Path part [/EACVBSDSFASFA] couldn't be encoded
at org.elasticsearch.client.RequestConverters$EndpointBuilder.encodePart(RequestConverters.java:1142)
at org.elasticsearch.client.RequestConverters$EndpointBuilder.addPathPart(RequestConverters.java:1104)
at org.elasticsearch.client.RequestConverters.endpoint(RequestConverters.java:704)
at org.elasticsearch.client.RequestConverters.index(RequestConverters.java:309)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1761)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1735)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1697)
at org.elasticsearch.client.RestHighLevelClient.index(RestHighLevelClient.java:929)
at 
.....
.....
Caused by: java.net.URISyntaxException: Illegal character in port number at index 30: 

The issue is not because of the field, but because you're using / as part of the id.问题不是因为该字段,而是因为您使用/作为 id 的一部分。

I'd guess this is a restriction to prevent resources with where IDs would have to be encoded, eg http://localhost:9200/index/_type/%2FEACVBSDSFASFA, note / -> %2F conversion.我猜这是一个限制,以防止必须对 ID 进行编码的资源,例如 http://localhost:9200/index/_type/%2FEACVBSDSFASFA,注意/ -> %2F转换。

In any case - prefer url-safe IDs, eg:在任何情况下 - 更喜欢 url 安全的 ID,例如:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用弹性搜索RestHighLevelClient在java中编写json映射? - How to write json mapping in java using elastic search RestHighLevelClient? 如何模拟 Java 弹性搜索连接服务的 RestHighLevelClient? - How to mock RestHighLevelClient for java elastic search connexion service? 弹性搜索:通过RestHighLevelClient连接时的java.net.ConnectException - Elastic search: java.net.ConnectException when connecting via RestHighLevelClient 将 json 字符串自定义查询设置为弹性搜索请求,java RestHighLevelClient - Set json string custom query to an elastic search request, java RestHighLevelClient Spring 引导 + 弹性搜索:Java RestHighLevelClient 拒绝连接 - Spring Boot + Elastic Search : Connection Refused with Java RestHighLevelClient 如何在弹性搜索中基于多字段值进行过滤 - How to filter based on multiple field value in elastic search java 如何使用 boolquery builder 进行弹性搜索特殊字符搜索 - How to do Elastic search special character search using boolquery builder 如何在Java字符串中搜索特殊字符? - How to search for a special character in java string? 如何在Java中添加对特殊Unicode字符的支持? - How to add support for a special unicode character in java? java - 如何在枚举中添加特殊字符? - java - How to add special character in enum?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM