Repository: searchbox-io/Jest
Pull request #221 (2015-07-11 21:27:31)

added document index, type and id to crud operations


Patch:
diff --git a/jest-common/src/main/java/io/searchbox/action/SingleResultAbstractDocumentTargetedAction.java b/jest-common/src/main/java/io/searchbox/action/SingleResultAbstractDocumentTargetedAction.java
new file mode 100644
index 00000000..c72542cc
--- /dev/null
+++ b/jest-common/src/main/java/io/searchbox/action/SingleResultAbstractDocumentTargetedAction.java
@@ -0,0 +1,18 @@
+package io.searchbox.action;
+
+import com.google.gson.Gson;
+import io.searchbox.core.DocumentResult;
+
+/**
+ * @author Bartosz Polnik
+ */
+public abstract class SingleResultAbstractDocumentTargetedAction extends AbstractDocumentTargetedAction<DocumentResult> {
+    public SingleResultAbstractDocumentTargetedAction(Builder builder) {
+        super(builder);
+    }
+
+    @Override
+    public DocumentResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) {
+        return createNewElasticSearchResult(new DocumentResult(gson), responseBody, statusCode, reasonPhrase, gson);
+    }
+}
diff --git a/jest-common/src/main/java/io/searchbox/client/JestClient.java b/jest-common/src/main/java/io/searchbox/client/JestClient.java
index 493eb30b..69d74583 100644
--- a/jest-common/src/main/java/io/searchbox/client/JestClient.java
+++ b/jest-common/src/main/java/io/searchbox/client/JestClient.java
@@ -14,7 +14,7 @@ public interface JestClient {
 
     <T extends JestResult> T execute(Action<T> clientRequest) throws IOException;
 
-    <T extends JestResult> void executeAsync(Action<T> clientRequest, JestResultHandler<T> jestResultHandler);
+    <T extends JestResult> void executeAsync(Action<T> clientRequest, JestResultHandler<? super T> jestResultHandler);
 
     void shutdownClient();
 
diff --git a/jest-common/src/main/java/io/searchbox/core/Delete.java b/jest-common/src/main/java/io/searchbox/core/Delete.java
index ff210475..41c645c1 100644
--- a/jest-common/src/main/java/io/searchbox/core/Delete.java
+++ b/jest-common/src/main/java/io/searchbox/core/Delete.java
@@ -1,15 +1,13 @@
 package io.searchbox.core;
 
-import io.searchbox.action.AbstractDocumentTargetedAction;
 import io.searchbox.action.BulkableAction;
-import io.searchbox.action.GenericResultAbstractDocumentTargetedAction;
-import io.searchbox.client.JestResult;
+import io.searchbox.action.SingleResultAbstractDocumentTargetedAction;
 
 /**
  * @author Dogukan Sonmez
  * @author cihat keser
  */
-public class Delete extends GenericResultAbstractDocumentTargetedAction implements BulkableAction<JestResult> {
+public class Delete extends SingleResultAbstractDocumentTargetedAction implements BulkableAction<DocumentResult> {
 
     protected Delete(Builder builder) {
         super(builder);
@@ -31,7 +29,7 @@ public class Delete extends GenericResultAbstractDocumentTargetedAction implemen
         return "delete";
     }
 
-    public static class Builder extends AbstractDocumentTargetedAction.Builder<Delete, Builder> {
+    public static class Builder extends SingleResultAbstractDocumentTargetedAction.Builder<Delete, Builder> {
 
         public Builder(String id) {
             this.id(id);
diff --git a/jest-common/src/main/java/io/searchbox/core/DocumentResult.java b/jest-common/src/main/java/io/searchbox/core/DocumentResult.java
new file mode 100644
index 00000000..dee5578c
--- /dev/null
+++ b/jest-common/src/main/java/io/searchbox/core/DocumentResult.java
@@ -0,0 +1,35 @@
+package io.searchbox.core;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import io.searchbox.client.JestResult;
+
+/**
+ * @author Bartosz Polnik
+ */
+public class DocumentResult extends JestResult {
+    public DocumentResult(Gson gson) {
+        super(gson);
+    }
+
+    public String getIndex() {
+        return getAsString(jsonObject.get("_index"));
+    }
+
+    public String getType() {
+        return getAsString(jsonObject.get("_type"));
+    }
+
+    public String getId() {
+        return getAsString(jsonObject.get("_id"));
+    }
+
+
+    private String getAsString(JsonElement jsonElement) {
+        if(jsonElement == null) {
+            return null;
+        } else {
+            return jsonElement.getAsString();
+        }
+    }
+}
diff --git a/jest-common/src/main/java/io/searchbox/core/Explain.java b/jest-common/src/main/java/io/searchbox/core/Explain.java
index b2578879..70db81e5 100644
--- a/jest-common/src/main/java/io/searchbox/core/Explain.java
+++ b/jest-common/src/main/java/io/searchbox/core/Explain.java
@@ -1,6 +1,6 @@
 package io.searchbox.core;
 
-import io.searchbox.action.GenericResultAbstractDocumentTargetedAction;
+import io.searchbox.action.SingleResultAbstractDocumentTargetedAction;
 import org.apache.commons.lang3.builder.EqualsBuilder;
 import org.apache.commons.lang3.builder.HashCodeBuilder;
 
@@ -8,7 +8,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
  * @author Dogukan Sonmez
  * @author cihat keser
  */
-public class Explain extends GenericResultAbstractDocumentTargetedAction {
+public class Explain extends SingleResultAbstractDocumentTargetedAction {
 
     protected Explain(Builder builder) {
         super(builder);
@@ -53,7 +53,7 @@ public class Explain extends GenericResultAbstractDocumentTargetedAction {
                 .isEquals();
     }
 
-    public static class Builder extends GenericResultAbstractDocumentTargetedAction.Builder<Explain, Builder> {
+    public static class Builder extends SingleResultAbstractDocumentTargetedAction.Builder<Explain, Builder> {
         private final Object query;
 
         public Builder(String index, String type, String id, Object query) {
diff --git a/jest-common/src/main/java/io/searchbox/core/Get.java b/jest-common/src/main/java/io/searchbox/core/Get.java
index 48eb7bdb..ecb9684f 100644
--- a/jest-common/src/main/java/io/searchbox/core/Get.java
+++ b/jest-common/src/main/java/io/searchbox/core/Get.java
@@ -1,13 +1,13 @@
 package io.searchbox.core;
 
-import io.searchbox.action.GenericResultAbstractDocumentTargetedAction;
+import io.searchbox.action.SingleResultAbstractDocumentTargetedAction;
 
 
 /**
  * @author Dogukan Sonmez
  * @author cihat keser
  */
-public class Get extends GenericResultAbstractDocumentTargetedAction {
+public class Get extends SingleResultAbstractDocumentTargetedAction {
 
     protected Get(Builder builder) {
         super(builder);
@@ -24,7 +24,7 @@ public class Get extends GenericResultAbstractDocumentTargetedAction {
         return "_source";
     }
 
-    public static class Builder extends GenericResultAbstractDocumentTargetedAction.Builder<Get, Builder> {
+    public static class Builder extends SingleResultAbstractDocumentTargetedAction.Builder<Get, Builder> {
 
         /**
          * Index and ID parameters are mandatory but type is optional (_all will be used for type if left blank).
diff --git a/jest-common/src/main/java/io/searchbox/core/Index.java b/jest-common/src/main/java/io/searchbox/core/Index.java
index cb0e7196..87b4eed2 100644
--- a/jest-common/src/main/java/io/searchbox/core/Index.java
+++ b/jest-common/src/main/java/io/searchbox/core/Index.java
@@ -1,8 +1,7 @@
 package io.searchbox.core;
 
 import io.searchbox.action.BulkableAction;
-import io.searchbox.action.GenericResultAbstractDocumentTargetedAction;
-import io.searchbox.client.JestResult;
+import io.searchbox.action.SingleResultAbstractDocumentTargetedAction;
 import io.searchbox.params.Parameters;
 import org.apache.commons.lang3.builder.EqualsBuilder;
 import org.apache.commons.lang3.builder.HashCodeBuilder;
@@ -13,7 +12,7 @@ import java.util.Collection;
  * @author Dogukan Sonmez
  * @author cihat keser
  */
-public class Index extends GenericResultAbstractDocumentTargetedAction implements BulkableAction<JestResult> {
+public class Index extends SingleResultAbstractDocumentTargetedAction implements BulkableAction<DocumentResult> {
 
     protected Index(Builder builder) {
         super(builder);
@@ -70,7 +69,7 @@ public class Index extends GenericResultAbstractDocumentTargetedAction implement
                 .isEquals();
     }
 
-    public static class Builder extends GenericResultAbstractDocumentTargetedAction.Builder<Index, Builder> {
+    public static class Builder extends SingleResultAbstractDocumentTargetedAction.Builder<Index, Builder> {
         private final Object source;
 
         public Builder(Object source) {
diff --git a/jest-common/src/main/java/io/searchbox/core/Update.java b/jest-common/src/main/java/io/searchbox/core/Update.java
index 412a5a41..f4ad063d 100644
--- a/jest-common/src/main/java/io/searchbox/core/Update.java
+++ b/jest-common/src/main/java/io/searchbox/core/Update.java
@@ -1,8 +1,7 @@
 package io.searchbox.core;
 
 import io.searchbox.action.BulkableAction;
-import io.searchbox.action.GenericResultAbstractDocumentTargetedAction;
-import io.searchbox.client.JestResult;
+import io.searchbox.action.SingleResultAbstractDocumentTargetedAction;
 import org.apache.commons.lang3.builder.EqualsBuilder;
 import org.apache.commons.lang3.builder.HashCodeBuilder;
 
@@ -10,7 +9,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
  * @author Dogukan Sonmez
  * @author cihat keser
  */
-public class Update extends GenericResultAbstractDocumentTargetedAction implements BulkableAction<JestResult> {
+public class Update extends SingleResultAbstractDocumentTargetedAction implements BulkableAction<DocumentResult> {
 
     protected Update(Builder builder) {
         super(builder);
@@ -65,7 +64,7 @@ public class Update extends GenericResultAbstractDocumentTargetedAction implemen
                 .isEquals();
     }
 
-    public static class Builder extends GenericResultAbstractDocumentTargetedAction.Builder<Update, Builder> {
+    public static class Builder extends SingleResultAbstractDocumentTargetedAction.Builder<Update, Builder> {
         private final Object payload;
 
         public Builder(Object payload) {
diff --git a/jest-droid/src/main/java/com/searchly/jestdroid/JestDroidClient.java b/jest-droid/src/main/java/com/searchly/jestdroid/JestDroidClient.java
index ca9bf0de..fcb451ef 100644
--- a/jest-droid/src/main/java/com/searchly/jestdroid/JestDroidClient.java
+++ b/jest-droid/src/main/java/com/searchly/jestdroid/JestDroidClient.java
@@ -64,7 +64,7 @@ public class JestDroidClient extends AbstractJestClient implements JestClient {
     }
 
     @Override
-    public <T extends JestResult> void executeAsync(final Action<T> clientRequest, final JestResultHandler<T> resultHandler) {
+    public <T extends JestResult> void executeAsync(final Action<T> clientRequest, final JestResultHandler<? super T> resultHandler) {
         throw new UnsupportedOperationException("Jest-droid does not yet support async execution, sorry!");
     }
 
diff --git a/jest/src/main/java/io/searchbox/client/http/JestHttpClient.java b/jest/src/main/java/io/searchbox/client/http/JestHttpClient.java
index be2897e2..d0b41a21 100755
--- a/jest/src/main/java/io/searchbox/client/http/JestHttpClient.java
+++ b/jest/src/main/java/io/searchbox/client/http/JestHttpClient.java
@@ -66,7 +66,7 @@ public class JestHttpClient extends AbstractJestClient implements JestClient {
     }
 
     @Override
-    public <T extends JestResult> void executeAsync(final Action<T> clientRequest, final JestResultHandler<T> resultHandler) {
+    public <T extends JestResult> void executeAsync(final Action<T> clientRequest, final JestResultHandler<? super T> resultHandler) {
         synchronized (this) {
             if (!asyncClient.isRunning()) {
                 asyncClient.start();
@@ -177,9 +177,9 @@ public class JestHttpClient extends AbstractJestClient implements JestClient {
 
     protected class DefaultCallback<T extends JestResult> implements FutureCallback<HttpResponse> {
         private final Action<T> clientRequest;
-        private final JestResultHandler<T> resultHandler;
+        private final JestResultHandler<? super T> resultHandler;
 
-        public DefaultCallback(Action<T> clientRequest, JestResultHandler<T> resultHandler) {
+        public DefaultCallback(Action<T> clientRequest, JestResultHandler<? super T> resultHandler) {
             this.clientRequest = clientRequest;
             this.resultHandler = resultHandler;
         }


Test patch:
diff --git a/jest-common/src/test/java/io/searchbox/client/AbstractJestClientTest.java b/jest-common/src/test/java/io/searchbox/client/AbstractJestClientTest.java
index 7788e768..ad7695f0 100644
--- a/jest-common/src/test/java/io/searchbox/client/AbstractJestClientTest.java
+++ b/jest-common/src/test/java/io/searchbox/client/AbstractJestClientTest.java
@@ -24,7 +24,7 @@ public class AbstractJestClientTest {
         }
 
         @Override
-        public <T extends JestResult> void executeAsync(final Action<T> clientRequest, final JestResultHandler<T> resultHandler) {
+        public <T extends JestResult> void executeAsync(final Action<T> clientRequest, final JestResultHandler<? super T> resultHandler) {
             // NOOP
         }
     };
diff --git a/jest-common/src/test/java/io/searchbox/core/DocumentResultTest.java b/jest-common/src/test/java/io/searchbox/core/DocumentResultTest.java
new file mode 100644
index 00000000..37c21c0f
--- /dev/null
+++ b/jest-common/src/test/java/io/searchbox/core/DocumentResultTest.java
@@ -0,0 +1,56 @@
+package io.searchbox.core;
+
+import com.google.gson.Gson;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+/**
+ * @author Bartosz Polnik
+ */
+public class DocumentResultTest {
+    static DocumentResult validResult = new DocumentResult(new Gson());
+    static DocumentResult invalidResult = new DocumentResult(new Gson());
+    static String validResponse = "{\n" +
+            "    \"_index\": \"testIndex\",\n" +
+            "    \"_type\": \"testType\",\n" +
+            "    \"_id\": \"testId\",\n" +
+            "    \"_version\": 2\n" +
+            "}";
+
+    static String invalidResponse = "{\n" +
+            "    \"error\": \"NullPointerException[null]\",\n" +
+            "    \"status\": 500\n" +
+            "}";
+
+    @BeforeClass
+    @SuppressWarnings("unchecked")
+    public static void setUp() {
+        validResult.setJsonMap(new Gson().fromJson(validResponse, Map.class));
+        invalidResult.setJsonMap(new Gson().fromJson(invalidResponse, Map.class));
+    }
+
+    @Test
+    public void shouldFetchIndexFromValidResponse() {
+        assertEquals("testIndex", validResult.getIndex());
+    }
+
+    @Test
+    public void shouldFetchTypeFromValidResponse() {
+        assertEquals("testType", validResult.getType());
+    }
+
+    @Test
+    public void shouldFetchIdFromValidResponse() {
+        assertEquals("testId", validResult.getId());
+    }
+
+    @Test
+    public void shouldReturnNullIndexOnInvalidResponse() {
+        assertNull(invalidResult.getIndex());
+    }
+}
\ No newline at end of file
diff --git a/jest/src/test/java/io/searchbox/core/DeleteIntegrationTest.java b/jest/src/test/java/io/searchbox/core/DeleteIntegrationTest.java
index ff82a467..a4893cb8 100644
--- a/jest/src/test/java/io/searchbox/core/DeleteIntegrationTest.java
+++ b/jest/src/test/java/io/searchbox/core/DeleteIntegrationTest.java
@@ -1,6 +1,5 @@
 package io.searchbox.core;
 
-import io.searchbox.client.JestResult;
 import io.searchbox.client.JestResultHandler;
 import io.searchbox.common.AbstractIntegrationTest;
 import org.elasticsearch.test.ElasticsearchIntegrationTest;
@@ -22,11 +21,14 @@ public class DeleteIntegrationTest extends AbstractIntegrationTest {
 
     @Test
     public void deleteDocument() throws IOException {
-        JestResult result = client.execute(new Delete.Builder("1")
+        DocumentResult result = client.execute(new Delete.Builder("1")
                 .index("twitter")
                 .type("tweet")
                 .build());
         assertFalse(result.isSucceeded());
+        assertEquals("twitter", result.getIndex());
+        assertEquals("tweet", result.getType());
+        assertEquals("1", result.getId());
     }
 
     @Ignore // async execution disturbs flow of the test suite
@@ -35,9 +37,9 @@ public class DeleteIntegrationTest extends AbstractIntegrationTest {
         client.executeAsync(new Delete.Builder("1")
                 .index("twitter")
                 .type("tweet")
-                .build(), new JestResultHandler<JestResult>() {
+                .build(), new JestResultHandler<DocumentResult>() {
             @Override
-            public void completed(JestResult result) {
+            public void completed(DocumentResult result) {
                 assertFalse(result.isSucceeded());
             }
 
@@ -52,12 +54,15 @@ public class DeleteIntegrationTest extends AbstractIntegrationTest {
     public void deleteRealDocument() throws IOException {
         Index index = new Index.Builder("{\"user\":\"kimchy\"}").index("cvbank").type("candidate").id("1").refresh(true).build();
         client.execute(index);
-        JestResult result = client.execute(new Delete.Builder("1")
+        DocumentResult result = client.execute(new Delete.Builder("1")
                 .index("cvbank")
                 .type("candidate")
                 .build());
 
         assertTrue(result.getErrorMessage(), result.isSucceeded());
+        assertEquals("cvbank", result.getIndex());
+        assertEquals("candidate", result.getType());
+        assertEquals("1", result.getId());
     }
 
 }
diff --git a/jest/src/test/java/io/searchbox/core/ExplainIntegrationTest.java b/jest/src/test/java/io/searchbox/core/ExplainIntegrationTest.java
index 31900627..8e4abbaa 100644
--- a/jest/src/test/java/io/searchbox/core/ExplainIntegrationTest.java
+++ b/jest/src/test/java/io/searchbox/core/ExplainIntegrationTest.java
@@ -1,6 +1,5 @@
 package io.searchbox.core;
 
-import io.searchbox.client.JestResult;
 import io.searchbox.common.AbstractIntegrationTest;
 import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.test.ElasticsearchIntegrationTest;
@@ -35,7 +34,10 @@ public class ExplainIntegrationTest extends AbstractIntegrationTest {
                 "}";
 
         Explain explain = new Explain.Builder("twitter", "tweet", "1", query).build();
-        JestResult result = client.execute(explain);
+        DocumentResult result = client.execute(explain);
         assertTrue(result.getErrorMessage(), result.isSucceeded());
+        assertEquals("twitter", result.getIndex());
+        assertEquals("tweet", result.getType());
+        assertEquals("1", result.getId());
     }
 }
diff --git a/jest/src/test/java/io/searchbox/core/GetIntegrationTest.java b/jest/src/test/java/io/searchbox/core/GetIntegrationTest.java
index dbe97be3..029fa9e9 100644
--- a/jest/src/test/java/io/searchbox/core/GetIntegrationTest.java
+++ b/jest/src/test/java/io/searchbox/core/GetIntegrationTest.java
@@ -1,7 +1,6 @@
 package io.searchbox.core;
 
 import io.searchbox.annotations.JestId;
-import io.searchbox.client.JestResult;
 import io.searchbox.client.JestResultHandler;
 import io.searchbox.common.AbstractIntegrationTest;
 import org.elasticsearch.action.index.IndexRequest;
@@ -11,7 +10,9 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author Dogukan Sonmez
@@ -36,19 +37,23 @@ public class GetIntegrationTest extends AbstractIntegrationTest {
 
     @Test
     public void getWithSpecialCharacterInDocId() throws IOException {
+        final String documentId = "asd/qwe";
         IndexResponse indexResponse = client().index(new IndexRequest(
                 INDEX,
                 TYPE,
-                "asd/qwe")
+                documentId)
                 .source("{\"user\":\"tweety\"}"))
                 .actionGet();
         assertNotNull(indexResponse);
 
-        JestResult result = client.execute(new Get.Builder(INDEX, "asd/qwe")
+        DocumentResult result = client.execute(new Get.Builder(INDEX, documentId)
                         .type(TYPE)
                         .build()
         );
         assertTrue(result.getErrorMessage(), result.isSucceeded());
+        assertEquals(INDEX, result.getIndex());
+        assertEquals(TYPE, result.getType());
+        assertEquals(documentId, result.getId());
     }
 
     @Test
@@ -59,7 +64,7 @@ public class GetIntegrationTest extends AbstractIntegrationTest {
         expectedTweet.setUserHash(id);
         expectedTweet.setMessage(message);
 
-        JestResult result = client.execute(new Index.Builder(expectedTweet).index(INDEX).type(TYPE).build());
+        DocumentResult result = client.execute(new Index.Builder(expectedTweet).index(INDEX).type(TYPE).build());
         assertTrue(result.getErrorMessage(), result.isSucceeded());
 
         Get get = new Get.Builder(INDEX, id).type(TYPE).build();
@@ -73,16 +78,21 @@ public class GetIntegrationTest extends AbstractIntegrationTest {
     @Test
     public void get() throws IOException {
         Get get = new Get.Builder(INDEX, "1").type(TYPE).build();
-        JestResult result = client.execute(get);
+        DocumentResult result = client.execute(get);
         assertTrue(result.getErrorMessage(), result.isSucceeded());
     }
 
     @Test
     public void getAsynchronously() throws InterruptedException, ExecutionException, IOException {
-        client.executeAsync(new Get.Builder(INDEX, "1").type(TYPE).build(), new JestResultHandler<JestResult>() {
+        final CountDownLatch completionChecker = new CountDownLatch(1);
+        client.executeAsync(new Get.Builder(INDEX, "1").type(TYPE).build(), new JestResultHandler<DocumentResult>() {
             @Override
-            public void completed(JestResult result) {
+            public void completed(DocumentResult result) {
                 assertTrue(result.getErrorMessage(), result.isSucceeded());
+                assertEquals(INDEX, result.getIndex());
+                assertEquals(TYPE, result.getType());
+                assertEquals("1", result.getId());
+                completionChecker.countDown();
             }
 
             @Override
@@ -91,42 +101,46 @@ public class GetIntegrationTest extends AbstractIntegrationTest {
             }
         });
 
-        //wait for asynchronous call
-        try {
-            Thread.sleep(1000);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
+        boolean finishedAsync = completionChecker.await(2, TimeUnit.SECONDS);
+        if (!finishedAsync) {
+            fail("Execution took to long to complete");
         }
     }
 
     @Test
     public void getWithType() throws Exception {
+        final String id = "testid1";
+        final String type = "article";
         TestArticleModel article = new TestArticleModel();
-        article.setId("testid1");
+        article.setId(id);
         article.setName("Jest");
-        Index index = new Index.Builder(article).index("articles").type("article").refresh(true).build();
-        JestResult indexResult = client.execute(index);
+        Index index = new Index.Builder(article).index("articles").type(type).refresh(true).build();
+        DocumentResult indexResult = client.execute(index);
         assertTrue(indexResult.getErrorMessage(), indexResult.isSucceeded());
 
-        JestResult result = client.execute(new Get.Builder("articles", "testid1").type("article").build());
+        DocumentResult result = client.execute(new Get.Builder("articles", "testid1").type(type).build());
+        assertEquals(type, result.getType());
         TestArticleModel articleResult = result.getSourceAsObject(TestArticleModel.class);
 
-        assertEquals(result.getJsonMap().get("_id"), articleResult.getId());
+        assertEquals(id, articleResult.getId());
     }
 
     @Test
     public void getWithoutType() throws Exception {
+        final String id = "testid1";
+        final String type = "article";
         TestArticleModel article = new TestArticleModel();
-        article.setId("testid1");
+        article.setId(id);
         article.setName("Jest");
-        Index index = new Index.Builder(article).index("articles").type("article").refresh(true).build();
-        JestResult indexResult = client.execute(index);
+        Index index = new Index.Builder(article).index("articles").type(type).refresh(true).build();
+        DocumentResult indexResult = client.execute(index);
         assertTrue(indexResult.getErrorMessage(), indexResult.isSucceeded());
 
-        JestResult result = client.execute(new Get.Builder("articles", "testid1").build());
+        DocumentResult result = client.execute(new Get.Builder("articles", "testid1").build());
+        assertEquals(type, result.getType());
         TestArticleModel articleResult = result.getSourceAsObject(TestArticleModel.class);
 
-        assertEquals(result.getJsonMap().get("_id"), articleResult.getId());
+        assertEquals(id, articleResult.getId());
     }
 
     class Tweet {
diff --git a/jest/src/test/java/io/searchbox/core/IndexIntegrationTest.java b/jest/src/test/java/io/searchbox/core/IndexIntegrationTest.java
index 24ca9035..a091055c 100644
--- a/jest/src/test/java/io/searchbox/core/IndexIntegrationTest.java
+++ b/jest/src/test/java/io/searchbox/core/IndexIntegrationTest.java
@@ -2,7 +2,6 @@ package io.searchbox.core;
 
 import com.google.common.collect.ImmutableMap;
 import io.searchbox.client.AbstractJestClient;
-import io.searchbox.client.JestResult;
 import io.searchbox.common.AbstractIntegrationTest;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
 import org.elasticsearch.action.get.GetResponse;
@@ -30,7 +29,7 @@ public class IndexIntegrationTest extends AbstractIntegrationTest {
         Map<String, String> source = ImmutableMap.of(
                 "test_name", "indexDocumentWithValidParametersAndWithoutSettings");
 
-        JestResult result = client.execute(
+        DocumentResult result = client.execute(
                 new Index.Builder(source)
                         .index(INDEX)
                         .type(TYPE)
@@ -39,6 +38,9 @@ public class IndexIntegrationTest extends AbstractIntegrationTest {
                         .build()
         );
         assertTrue(result.getErrorMessage(), result.isSucceeded());
+        assertEquals(INDEX, result.getIndex());
+        assertEquals(TYPE, result.getType());
+        assertEquals(id, result.getId());
 
         GetResponse getResponse = get(INDEX, TYPE, id);
         assertTrue(getResponse.isExists());
@@ -50,7 +52,7 @@ public class IndexIntegrationTest extends AbstractIntegrationTest {
     public void automaticIdGeneration() throws IOException {
         Map<String, String> source = ImmutableMap.of("test_name", "automaticIdGeneration");
 
-        JestResult result = client.execute(
+        DocumentResult result = client.execute(
                 new Index.Builder(source)
                         .index(INDEX)
                         .type(TYPE)
@@ -59,7 +61,7 @@ public class IndexIntegrationTest extends AbstractIntegrationTest {
         );
         assertTrue(result.getErrorMessage(), result.isSucceeded());
 
-        String id = (String) result.getValue("_id");
+        String id = result.getId();
         GetResponse getResponse = get(INDEX, TYPE, id);
         assertTrue(getResponse.isExists());
         assertFalse(getResponse.isSourceEmpty());
@@ -79,7 +81,7 @@ public class IndexIntegrationTest extends AbstractIntegrationTest {
                 .type(TYPE).source(mapping)).actionGet().isAcknowledged());
         waitForConcreteMappingsOnAll(INDEX, TYPE, "creationDate");
 
-        JestResult result = client.execute(new Index.Builder(source).index(INDEX).type(TYPE).id(id).build());
+        DocumentResult result = client.execute(new Index.Builder(source).index(INDEX).type(TYPE).id(id).build());
         assertTrue(result.getErrorMessage(), result.isSucceeded());
 
         GetResponse getResponse = get(INDEX, TYPE, id);
diff --git a/jest/src/test/java/io/searchbox/core/UpdateIntegrationTest.java b/jest/src/test/java/io/searchbox/core/UpdateIntegrationTest.java
index e6c78db9..58b00b17 100644
--- a/jest/src/test/java/io/searchbox/core/UpdateIntegrationTest.java
+++ b/jest/src/test/java/io/searchbox/core/UpdateIntegrationTest.java
@@ -1,7 +1,6 @@
 package io.searchbox.core;
 
 
-import io.searchbox.client.JestResult;
 import io.searchbox.common.AbstractIntegrationTest;
 import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.test.ElasticsearchIntegrationTest;
@@ -31,10 +30,13 @@ public class UpdateIntegrationTest extends AbstractIntegrationTest {
                         .refresh(true)
         ).actionGet();
 
-        JestResult result = client.execute(new Update.Builder(script).index("twitter").type("tweet").id("1").build());
+        DocumentResult result = client.execute(new Update.Builder(script).index("twitter").type("tweet").id("1").build());
         assertTrue(result.getErrorMessage(), result.isSucceeded());
+        assertEquals("twitter", result.getIndex());
+        assertEquals("tweet", result.getType());
+        assertEquals("1", result.getId());
 
-        JestResult getResult = client.execute(new Get.Builder("twitter", "1").type("tweet").build());
+        DocumentResult getResult = client.execute(new Get.Builder("twitter", "1").type("tweet").build());
         assertEquals("That is testblue", ((Map) getResult.getValue("_source")).get("tags"));
     }
 }