Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 56edc60

Browse files
committed
Document id is no longer encoded while creating documents to match Jest behavior to ES. (See release notes).
Test case added for testing new non-encoded id behavior.
1 parent e6e49b1 commit 56edc60

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

jest-common/src/main/java/io/searchbox/action/AbstractDocumentTargetedAction.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import io.searchbox.client.config.ElasticsearchVersion;
55
import io.searchbox.strings.StringUtils;
66

7-
import java.io.UnsupportedEncodingException;
8-
import java.net.URLEncoder;
9-
107
/**
118
* @author cihat keser
129
*/
@@ -41,11 +38,7 @@ protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
4138
StringBuilder sb = new StringBuilder(super.buildURI(elasticsearchVersion));
4239

4340
if (StringUtils.isNotBlank(id)) {
44-
try {
45-
sb.append("/").append(URLEncoder.encode(id, CHARSET));
46-
} catch (UnsupportedEncodingException e) {
47-
log.error("Error occurred while adding document id to uri.", e);
48-
}
41+
sb.append("/").append(id);
4942
}
5043
return sb.toString();
5144
}

jest/src/test/java/io/searchbox/core/SearchIntegrationTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,26 @@ public void searchIndexWithTypeWithNullJestId() throws Exception {
285285
assertNotNull(articleResult.get(0).getId());
286286
}
287287

288+
@Test
289+
public void testWithEncodedURI() throws IOException {
290+
assertAcked(prepareCreate(INDEX).addMapping(TYPE, "{\"properties\":{\"user\":{\"type\":\"keyword\"}}}", XContentType.JSON));
291+
292+
Index index = new Index.Builder("{\"user\":\"kimchy1\"}").index(INDEX).type(TYPE).id("test%2f1").refresh(true).build();
293+
client.execute(index);
294+
295+
String query = "{\n" +
296+
" \"query\": {\n" +
297+
" \"terms\": {\n" +
298+
" \"_id\": [\"test/1\"]\n" +
299+
" }\n" +
300+
" }\n" +
301+
"}";
302+
303+
SearchResult result = client.execute(new Search.Builder(query).build());
304+
assertTrue(result.getErrorMessage(), result.isSucceeded());
305+
assertEquals(Long.valueOf(1), result.getTotal());
306+
}
307+
288308
@Test
289309
public void searchWithPercolator() throws IOException {
290310
String index = "twitter";

0 commit comments

Comments
 (0)