Skip to content

Commit c5febc3

Browse files
committed
Disabling allow_explicit_index breaks bulk
fixes elastic#4668
1 parent b67892e commit c5febc3

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/main/java/org/elasticsearch/action/bulk/BulkRequest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,6 @@ public BulkRequest add(BytesReference data, boolean contentUnsafe, @Nullable Str
341341
// we use internalAdd so we don't fork here, this allows us not to copy over the big byte array to small chunks
342342
// of index request. All index requests are still unsafe if applicable.
343343
if ("index".equals(action)) {
344-
if (!allowExplicitIndex) {
345-
throw new ElasticSearchIllegalArgumentException("explicit index in bulk is not allowed");
346-
}
347344
if (opType == null) {
348345
internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).timestamp(timestamp).ttl(ttl).version(version).versionType(versionType)
349346
.source(data.slice(from, nextMarker - from), contentUnsafe)

src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.junit.Test;
2929

3030
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
31-
import static org.hamcrest.MatcherAssert.assertThat;
3231
import static org.hamcrest.Matchers.equalTo;
3332
import static org.hamcrest.Matchers.instanceOf;
3433

@@ -80,4 +79,17 @@ public void testSimpleBulk4() throws Exception {
8079
assertThat(((UpdateRequest) bulkRequest.requests().get(1)).upsertRequest().source().toUtf8(), equalTo("{\"counter\":1}"));
8180
}
8281

82+
@Test
83+
public void testBulkAllowExplicitIndex() throws Exception {
84+
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk.json");
85+
try {
86+
new BulkRequest().add(new BytesArray(bulkAction.getBytes(Charsets.UTF_8)), true, null, null, false);
87+
assert false;
88+
} catch (Exception e) {
89+
90+
}
91+
92+
bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk5.json");
93+
new BulkRequest().add(new BytesArray(bulkAction.getBytes(Charsets.UTF_8)), true, "test", null, false);
94+
}
8395
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{ "index": {
2+
"_type": "type1",
3+
"_id": "1"
4+
} }
5+
{ "field1" : "value1" }
6+
{ "delete" : { "_type" : "type1", "_id" : "2" } }
7+
{ "create" : { "_type" : "type1", "_id" : "3" } }
8+
{ "field1" : "value3" }

0 commit comments

Comments
 (0)