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

Commit

Permalink
Merge pull request #174 from tomsen-san/issue-142-JestId-missing
Browse files Browse the repository at this point in the history
bugfix: #142 jest id missing
  • Loading branch information
Cihat Keser committed Jan 22, 2015
2 parents 7db9bf9 + 61751eb commit 396cfb7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jest-common/src/main/java/io/searchbox/client/JestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ protected List<JsonElement> extractSource() {
}
}
} else if (obj != null) {
JsonElement objId = jsonObject.get("_id");
if ((objId != null) && obj.isJsonObject()) {
obj.getAsJsonObject().add(ES_METADATA_ID, objId);
}
sourceList.add(obj);
}
}
Expand Down
26 changes: 26 additions & 0 deletions jest-common/src/test/java/io/searchbox/client/JestResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void extractGetResource() {
expectedResultMap.put("user", "kimchy");
expectedResultMap.put("postDate", "2009-11-15T14:12:12");
expectedResultMap.put("message", "trying out Elastic Search");
expectedResultMap.put(JestResult.ES_METADATA_ID, "1");
JsonObject actualResultMap = result.extractSource().get(0).getAsJsonObject();
assertEquals(expectedResultMap.size(), actualResultMap.entrySet().size());
for (String key : expectedResultMap.keySet()) {
Expand Down Expand Up @@ -68,6 +69,31 @@ public void extractGetResourceWithLongId() {
assertEquals(new Long(Integer.MAX_VALUE + 10l), actual.getSomeIdName());
}


@Test
public void extractGetResourceWithLongIdNotInSource() {
Long actualId = Integer.MAX_VALUE + 10l;

String response = "{\n" +
" \"_index\" : \"blog\",\n" +
" \"_type\" : \"comment\",\n" +
" \"_id\" : \"" + actualId.toString() + "\", \n" +
" \"_source\" : {\n" +
" \"message\" : \"trying out Elastic Search\"\n" +
" }\n" +
"}\n";
result.setJsonMap(new Gson().fromJson(response, Map.class));
result.setPathToResult("_source");
result.setSucceeded(true);

Comment actual = result.getSourceAsObject(Comment.class);
assertNotNull(actual);

assertEquals(new Long(Integer.MAX_VALUE + 10l), actual.getSomeIdName());
}



@Test
public void extractUnFoundGetResource() {
String response = "{\"_index\":\"twitter\",\"_type\":\"tweet\",\"_id\":\"13333\",\"exists\":false}";
Expand Down

0 comments on commit 396cfb7

Please sign in to comment.