Disabling allow_explicit_index breaks bulk

fixes #4668
This commit is contained in:
Shay Banon 2014-01-09 17:10:41 +01:00
parent 01b18ad219
commit dfdf269a3f
3 changed files with 21 additions and 4 deletions

View File

@ -339,9 +339,6 @@ public class BulkRequest extends ActionRequest<BulkRequest> {
// 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);

View File

@ -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);
}
}

View File

@ -0,0 +1,8 @@
{ "index": {
"_type": "type1",
"_id": "1"
} }
{ "field1" : "value1" }
{ "delete" : { "_type" : "type1", "_id" : "2" } }
{ "create" : { "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }