Skip to content

Commit

Permalink
Document id is no longer encoded while creating documents to match Je…
Browse files Browse the repository at this point in the history
…st behavior to ES. (See release notes).

Test case added for testing new non-encoded id behavior.
  • Loading branch information
musabgelisgen committed Aug 7, 2018
1 parent e6e49b1 commit 56edc60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import io.searchbox.client.config.ElasticsearchVersion;
import io.searchbox.strings.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
* @author cihat keser
*/
Expand Down Expand Up @@ -41,11 +38,7 @@ protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
StringBuilder sb = new StringBuilder(super.buildURI(elasticsearchVersion));

if (StringUtils.isNotBlank(id)) {
try {
sb.append("/").append(URLEncoder.encode(id, CHARSET));
} catch (UnsupportedEncodingException e) {
log.error("Error occurred while adding document id to uri.", e);
}
sb.append("/").append(id);
}
return sb.toString();
}
Expand Down
20 changes: 20 additions & 0 deletions jest/src/test/java/io/searchbox/core/SearchIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,26 @@ public void searchIndexWithTypeWithNullJestId() throws Exception {
assertNotNull(articleResult.get(0).getId());
}

@Test
public void testWithEncodedURI() throws IOException {
assertAcked(prepareCreate(INDEX).addMapping(TYPE, "{\"properties\":{\"user\":{\"type\":\"keyword\"}}}", XContentType.JSON));

Index index = new Index.Builder("{\"user\":\"kimchy1\"}").index(INDEX).type(TYPE).id("test%2f1").refresh(true).build();
client.execute(index);

String query = "{\n" +
" \"query\": {\n" +
" \"terms\": {\n" +
" \"_id\": [\"test/1\"]\n" +
" }\n" +
" }\n" +
"}";

SearchResult result = client.execute(new Search.Builder(query).build());
assertTrue(result.getErrorMessage(), result.isSucceeded());
assertEquals(Long.valueOf(1), result.getTotal());
}

@Test
public void searchWithPercolator() throws IOException {
String index = "twitter";
Expand Down

0 comments on commit 56edc60

Please sign in to comment.