Skip to content

Commit

Permalink
Bulk: allow null values in action/metadata line parameters
Browse files Browse the repository at this point in the history
Closes #11458
  • Loading branch information
tlrx committed Jun 2, 2015
1 parent 0b57f46 commit bfceaa6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Expand Up @@ -332,7 +332,7 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
} else {
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains an unknown parameter [" + currentFieldName + "]");
}
} else {
} else if (token != XContentParser.Token.VALUE_NULL) {
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
}
}
Expand Down
Expand Up @@ -177,4 +177,12 @@ public void testSimpleBulk9() throws Exception {
e.getMessage().contains("Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found [START_ARRAY]"), equalTo(true));
}
}

@Test
public void testSimpleBulk10() throws Exception {
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk10.json");
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(bulkAction.getBytes(Charsets.UTF_8), 0, bulkAction.length(), null, null);
assertThat(bulkRequest.numberOfActions(), equalTo(9));
}
}
15 changes: 15 additions & 0 deletions src/test/java/org/elasticsearch/action/bulk/simple-bulk10.json
@@ -0,0 +1,15 @@
{ "index" : {"_index":null, "_type":"type1", "_id":"0"} }
{ "field1" : "value1" }
{ "index" : {"_index":"test", "_type":null, "_id":"0"} }
{ "field1" : "value1" }
{ "index" : {"_index":"test", "_type":"type1", "_id":null} }
{ "field1" : "value1" }
{ "delete" : {"_index":null, "_type":"type1", "_id":"0"} }
{ "delete" : {"_index":"test", "_type":null, "_id":"0"} }
{ "delete" : {"_index":"test", "_type":"type1", "_id":null} }
{ "create" : {"_index":null, "_type":"type1", "_id":"0"} }
{ "field1" : "value1" }
{ "create" : {"_index":"test", "_type":null, "_id":"0"} }
{ "field1" : "value1" }
{ "create" : {"_index":"test", "_type":"type1", "_id":null} }
{ "field1" : "value1" }

0 comments on commit bfceaa6

Please sign in to comment.