diff --git a/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java b/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java index 532e55603c8..2927419fb7b 100644 --- a/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java +++ b/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java @@ -339,9 +339,6 @@ public class BulkRequest extends ActionRequest { // we use internalAdd so we don't fork here, this allows us not to copy over the big byte array to small chunks // of index request. All index requests are still unsafe if applicable. if ("index".equals(action)) { - if (!allowExplicitIndex) { - throw new ElasticsearchIllegalArgumentException("explicit index in bulk is not allowed"); - } if (opType == null) { internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).timestamp(timestamp).ttl(ttl).version(version).versionType(versionType) .source(data.slice(from, nextMarker - from), contentUnsafe), payload); diff --git a/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java b/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java index b26a075ca06..29c26d4e034 100644 --- a/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java +++ b/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java @@ -28,7 +28,6 @@ import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; @@ -80,4 +79,17 @@ public class BulkRequestTests extends ElasticsearchTestCase { assertThat(((UpdateRequest) bulkRequest.requests().get(1)).upsertRequest().source().toUtf8(), equalTo("{\"counter\":1}")); } + @Test + public void testBulkAllowExplicitIndex() throws Exception { + String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk.json"); + try { + new BulkRequest().add(new BytesArray(bulkAction.getBytes(Charsets.UTF_8)), true, null, null, false); + assert false; + } catch (Exception e) { + + } + + bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk5.json"); + new BulkRequest().add(new BytesArray(bulkAction.getBytes(Charsets.UTF_8)), true, "test", null, false); + } } diff --git a/src/test/java/org/elasticsearch/action/bulk/simple-bulk5.json b/src/test/java/org/elasticsearch/action/bulk/simple-bulk5.json new file mode 100644 index 00000000000..d3ec217a8ae --- /dev/null +++ b/src/test/java/org/elasticsearch/action/bulk/simple-bulk5.json @@ -0,0 +1,8 @@ +{ "index": { + "_type": "type1", + "_id": "1" +} } +{ "field1" : "value1" } +{ "delete" : { "_type" : "type1", "_id" : "2" } } +{ "create" : { "_type" : "type1", "_id" : "3" } } +{ "field1" : "value3" }