【问题标题】:Java RestHighLevelClient - Elastic Search - How to add special character '/' in id field valueJava RestHighLevelClient - 弹性搜索 - 如何在 id 字段值中添加特殊字符“/”
【发布时间】:2021-07-01 14:43:46
【问题描述】:

在弹性搜索中使用“/”插入字段值时出现异常

代码:

String id = "/EACVBSDSFASFA";

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

例外:

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: 

【问题讨论】:

    标签: java elasticsearch aws-elasticsearch resthighlevelclient


    【解决方案1】:

    问题不是因为字段,而是因为您使用 / 作为 id 的一部分。

    我猜这是一个限制,以防止必须对 ID 进行编码的资源,例如http://localhost:9200/index/_type/%2FEACVBSDSFASFA,注意/ -> %2F 转换。

    无论如何 - 首选 url-safe ID,例如:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-03
      • 1970-01-01
      • 2023-02-15
      • 1970-01-01
      相关资源
      最近更新 更多