[英]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,例如:
+
, =
, /
are replaced with URI-safe characters.如果您想使用 base64 ID,请使用它的 base64url 版本 - https://en.wikipedia.org/wiki/Base64#URL_applications其中+
、 =
、 /
替换为 URI 安全字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.