nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: searchbox-io/Jest
Pull request #174 (2015-01-21 22:12:10)

bugfix: #142 jest id missing
@kramer I did as you suggested. The one-liner turned out to be a several liner due to some broken tests. I also added a unit test for the issue in JestResultTest and fixed another. Pls comment. 


Patch:
diff --git a/jest-common/src/main/java/io/searchbox/client/JestResult.java b/jest-common/src/main/java/io/searchbox/client/JestResult.java
index 8133145a..7145fcab 100644
--- a/jest-common/src/main/java/io/searchbox/client/JestResult.java
+++ b/jest-common/src/main/java/io/searchbox/client/JestResult.java
@@ -158,6 +158,10 @@ public class JestResult {
                         }
                     }
                 } else if (obj != null) {
+                    JsonElement objId = jsonObject.get("_id");
+                    if ((objId != null) && obj.isJsonObject()) {
+                        obj.getAsJsonObject().add(ES_METADATA_ID, objId);
+                    }
                     sourceList.add(obj);
                 }
             }


Test patch:
diff --git a/jest-common/src/test/java/io/searchbox/client/JestResultTest.java b/jest-common/src/test/java/io/searchbox/client/JestResultTest.java
index 203ec34b..19c0a0af 100644
--- a/jest-common/src/test/java/io/searchbox/client/JestResultTest.java
+++ b/jest-common/src/test/java/io/searchbox/client/JestResultTest.java
@@ -38,6 +38,7 @@ public class JestResultTest {
         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()) {
@@ -68,6 +69,31 @@ public class JestResultTest {
         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}";
Repository: searchbox-io/Jest
Pull request #190 (2015-03-17 15:04:56)

 #186 Implementation of DeleteMapping


Patch:
diff --git a/jest-common/src/main/java/io/searchbox/indices/mapping/DeleteMapping.java b/jest-common/src/main/java/io/searchbox/indices/mapping/DeleteMapping.java
index 9346309a..b34b7464 100644
--- a/jest-common/src/main/java/io/searchbox/indices/mapping/DeleteMapping.java
+++ b/jest-common/src/main/java/io/searchbox/indices/mapping/DeleteMapping.java
@@ -1,9 +1,46 @@
 package io.searchbox.indices.mapping;
 
+
+import io.searchbox.action.GenericResultAbstractAction;
+
 /**
  * @author Dogukan Sonmez
+ * @author François Thareau
  */
+public class DeleteMapping extends GenericResultAbstractAction {
+
+    public DeleteMapping(Builder builder) {
+        super(builder);
+
+        this.indexName = builder.index;
+        this.typeName = builder.type;
+        setURI(buildURI());
+    }
+
+    @Override
+    protected String buildURI() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(super.buildURI()).append("/_mapping");
+        return sb.toString();
+    }
+
+    @Override
+    public String getRestMethodName() {
+        return "DELETE";
+    }
+
+    public static class Builder extends GenericResultAbstractAction.Builder<DeleteMapping, Builder> {
+        private String index;
+        private String type;
 
+        public Builder(String index, String type) {
+            this.index = index;
+            this.type = type;
+        }
 
-public class DeleteMapping {
+        @Override
+        public DeleteMapping build() {
+            return new DeleteMapping(this);
+        }
+    }
 }


Test patch:
diff --git a/jest-common/src/test/java/io/searchbox/indices/mapping/DeleteMappingTest.java b/jest-common/src/test/java/io/searchbox/indices/mapping/DeleteMappingTest.java
new file mode 100644
index 00000000..a82b458c
--- /dev/null
+++ b/jest-common/src/test/java/io/searchbox/indices/mapping/DeleteMappingTest.java
@@ -0,0 +1,34 @@
+package io.searchbox.indices.mapping;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public class DeleteMappingTest {
+
+    @Test
+    public void testBasicUriGeneration() {
+        DeleteMapping deleteMapping = new DeleteMapping.Builder("twitter","tweet").build();
+
+        assertEquals("DELETE", deleteMapping.getRestMethodName());
+        assertEquals("twitter/tweet/_mapping", deleteMapping.getURI());
+    }
+
+    @Test
+    public void equalsReturnsTrueForSameIndex() {
+        DeleteMapping deleteMapping1 = new DeleteMapping.Builder("twitter","tweet").build();
+        DeleteMapping deleteMapping1Duplicate = new DeleteMapping.Builder("twitter","tweet").build();
+
+        assertEquals(deleteMapping1, deleteMapping1Duplicate);
+    }
+
+    @Test
+    public void equalsReturnsFalseForDifferentIndex() {
+        DeleteMapping deleteMapping1 = new DeleteMapping.Builder("twitter","tweet").build();
+        DeleteMapping deleteMapping2 = new DeleteMapping.Builder("twitter","myspace").build();
+
+        assertNotEquals(deleteMapping1, deleteMapping2);
+    }
+
+}
\ No newline at end of file
Repository: searchbox-io/Jest
Pull request #336 (2016-04-14 10:58:27)

Fix NPE when bulk item result has "_id":null
When an item fails in bulk indexing, trying to getItems() from BulkResult throws NPE.


Patch:
diff --git a/jest-common/src/main/java/io/searchbox/core/BulkResult.java b/jest-common/src/main/java/io/searchbox/core/BulkResult.java
index 23840f27..12f82b3e 100644
--- a/jest-common/src/main/java/io/searchbox/core/BulkResult.java
+++ b/jest-common/src/main/java/io/searchbox/core/BulkResult.java
@@ -93,7 +93,7 @@ public class BulkResult extends JestResult {
             this.operation = operation;
             this.index = values.get("_index").getAsString();
             this.type = values.get("_type").getAsString();
-            this.id = values.get("_id").getAsString();
+            this.id = values.has("_id") && !values.get("_id").isJsonNull() ? values.get("_id").getAsString() : null;
             this.status = values.get("status").getAsInt();
             this.error = values.has("error") ? values.get("error").toString() : null;
         }


Test patch:
diff --git a/jest-common/src/test/java/io/searchbox/core/BulkResultTest.java b/jest-common/src/test/java/io/searchbox/core/BulkResultTest.java
new file mode 100644
index 00000000..86645dcf
--- /dev/null
+++ b/jest-common/src/test/java/io/searchbox/core/BulkResultTest.java
@@ -0,0 +1,40 @@
+package io.searchbox.core;
+
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+public class BulkResultTest {
+
+    static String indexFailedResult = "{\n" +
+            "    \"took\": 10,\n" +
+            "    \"errors\": true,\n" +
+            "    \"items\": [\n" +
+            "        {\n" +
+            "            \"index\": {\n" +
+            "                \"_index\": \"index-name\",\n" +
+            "                \"_type\": \"type-name\",\n" +
+            "                \"_id\": null,\n" +
+            "                \"status\": 400,\n" +
+            "                \"error\": \"MapperParsingException[mapping [type-name]]; nested: MapperParsingException[No type specified for property [field-name]]; \"\n" +
+            "            }\n" +
+            "        }\n" +
+            "    ]\n" +
+            "}";
+
+    @Test
+    public void bulkResultWithFailures() {
+        BulkResult bulkResult = new BulkResult(new GsonBuilder().serializeNulls().create());
+        bulkResult.setJsonString(indexFailedResult);
+        bulkResult.setJsonMap(new Gson().fromJson(indexFailedResult, Map.class));
+        bulkResult.setSucceeded(false);
+
+        assertEquals(1, bulkResult.getItems().size());
+        assertEquals(1, bulkResult.getFailedItems().size());
+    }
+}
Repository: searchbox-io/Jest
Pull request #418 (2016-11-21 12:36:30)

GH-417 Add accept header to _cat API requests to support ES5


Patch:
diff --git a/jest-common/src/main/java/io/searchbox/core/Cat.java b/jest-common/src/main/java/io/searchbox/core/Cat.java
index 4c256f97..ea635b78 100644
--- a/jest-common/src/main/java/io/searchbox/core/Cat.java
+++ b/jest-common/src/main/java/io/searchbox/core/Cat.java
@@ -63,6 +63,7 @@ public class Cat extends AbstractAction<CatResult> {
         private static final String operationPath = "indices";
 
         public IndicesBuilder() {
+            setHeader("accept", "application/json");
             setHeader("content-type", "application/json");
         }
 
@@ -80,6 +81,7 @@ public class Cat extends AbstractAction<CatResult> {
     public static class AliasesBuilder extends AbstractMultiIndexActionBuilder<Cat, AliasesBuilder> implements CatBuilder {
         private static final String operationPath = "aliases";
         public AliasesBuilder() {
+            setHeader("accept", "application/json");
             setHeader("content-type", "application/json");
         }
 


Test patch:
diff --git a/jest-common/src/test/java/io/searchbox/core/CatAliasesBuilderTest.java b/jest-common/src/test/java/io/searchbox/core/CatAliasesBuilderTest.java
index 2b58a9ba..f16715cc 100644
--- a/jest-common/src/test/java/io/searchbox/core/CatAliasesBuilderTest.java
+++ b/jest-common/src/test/java/io/searchbox/core/CatAliasesBuilderTest.java
@@ -11,6 +11,7 @@ public class CatAliasesBuilderTest {
     @Test
     public void shouldSetApplicationJsonHeader() {
         Cat cat = new Cat.AliasesBuilder().build();
+        assertEquals("application/json", cat.getHeader("accept"));
         assertEquals("application/json", cat.getHeader("content-type"));
     }
 
diff --git a/jest-common/src/test/java/io/searchbox/core/CatIndicesBuilderTest.java b/jest-common/src/test/java/io/searchbox/core/CatIndicesBuilderTest.java
index aba3bff6..ebbf6ebf 100644
--- a/jest-common/src/test/java/io/searchbox/core/CatIndicesBuilderTest.java
+++ b/jest-common/src/test/java/io/searchbox/core/CatIndicesBuilderTest.java
@@ -11,6 +11,7 @@ public class CatIndicesBuilderTest {
     @Test
     public void shouldSetApplicationJsonHeader() {
         Cat cat = new Cat.IndicesBuilder().build();
+        assertEquals("application/json", cat.getHeader("accept"));
         assertEquals("application/json", cat.getHeader("content-type"));
     }
Repository: searchbox-io/Jest
Pull request #552 (2017-10-02 12:23:23)

Fixing JsonNull exception in case of null maxscore.
Max score is null in case of custom sorting.

Issue: https://github.com/searchbox-io/Jest/issues/433


Patch:
diff --git a/jest-common/src/main/java/io/searchbox/core/SearchResult.java b/jest-common/src/main/java/io/searchbox/core/SearchResult.java
index 5822cb62..6fa21ab5 100644
--- a/jest-common/src/main/java/io/searchbox/core/SearchResult.java
+++ b/jest-common/src/main/java/io/searchbox/core/SearchResult.java
@@ -209,7 +209,7 @@ public class SearchResult extends JestResult {
     public Float getMaxScore() {
         Float maxScore = null;
         JsonElement obj = getPath(PATH_TO_MAX_SCORE);
-        if (obj != null) maxScore = obj.getAsFloat();
+        if (obj != null && !obj.isJsonNull()) maxScore = obj.getAsFloat();
         return maxScore;
     }
 


Test patch:
diff --git a/jest-common/src/test/java/io/searchbox/core/SearchResultTest.java b/jest-common/src/test/java/io/searchbox/core/SearchResultTest.java
index 7acd8a1e..0cff9d6f 100644
--- a/jest-common/src/test/java/io/searchbox/core/SearchResultTest.java
+++ b/jest-common/src/test/java/io/searchbox/core/SearchResultTest.java
@@ -58,6 +58,41 @@ public class SearchResultTest {
         assertNull(maxScore);
     }
 
+    @Test
+    public void testGetMaxScoreNullMaxScore() {
+        String jsonWithNullMaxScore = "{\n" +
+                "    \"_shards\":{\n" +
+                "        \"total\" : 5,\n" +
+                "        \"successful\" : 5,\n" +
+                "        \"failed\" : 0\n" +
+                "    },\n" +
+                "    \"hits\":{\n" +
+                "        \"max_score\" : null,\n" +
+                "        \"total\" : 1,\n" +
+                "        \"hits\" : [\n" +
+                "            {\n" +
+                "                \"_index\" : \"twitter\",\n" +
+                "                \"_type\" : \"tweet\",\n" +
+                "                \"_id\" : \"1\",\n" +
+                "                \"_source\" : {\n" +
+                "                    \"user\" : \"kimchy\",\n" +
+                "                    \"postDate\" : \"2009-11-15T14:12:12\",\n" +
+                "                    \"message\" : \"trying out Elasticsearch\"\n" +
+                "                }\n" +
+                "            }\n" +
+                "        ]\n" +
+                "    }\n" +
+                "}";
+        SearchResult searchResult = new SearchResult(new Gson());
+        searchResult.setSucceeded(true);
+        searchResult.setJsonString(jsonWithNullMaxScore);
+        searchResult.setJsonObject(new JsonParser().parse(jsonWithNullMaxScore).getAsJsonObject());
+        searchResult.setPathToResult("hits/hits/_source");
+
+        Float maxScore = searchResult.getMaxScore();
+        assertNull(maxScore);
+    }
+
     @Test
     public void testGetMaxScore() {
         String jsonWithMaxScore = "{\n" +