File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
main/java/org/elasticsearch/action/admin/indices/mapping/put
test/java/org/elasticsearch/action/admin/indices/mapping/put Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,17 @@ public PutMappingRequest source(Object... source) {
177177 return source (buildFromSimplifiedDef (type , source ));
178178 }
179179
180+ /**
181+ * @param type the mapping type
182+ * @param source consisting of field/properties pairs (e.g. "field1",
183+ * "type=string,store=true"). If the number of arguments is not
184+ * divisible by two an {@link IllegalArgumentException} is thrown
185+ * @return the mappings definition
186+ */
180187 public static XContentBuilder buildFromSimplifiedDef (String type , Object ... source ) {
188+ if (source .length % 2 != 0 ) {
189+ throw new IllegalArgumentException ("mapping source must be pairs of fieldnames and properties definition." );
190+ }
181191 try {
182192 XContentBuilder builder = XContentFactory .jsonBuilder ();
183193 builder .startObject ();
Original file line number Diff line number Diff line change @@ -57,4 +57,11 @@ public void testValidation() {
5757 "Validation Failed: 1: either concrete index or unresolved indices can be set," +
5858 " concrete index: [[foo/bar]] and indices: [myindex];" );
5959 }
60+
61+ public void testBuildFromSimplifiedDef () {
62+ // test that method rejects input where input varargs fieldname/properites are not paired correctly
63+ IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
64+ () -> PutMappingRequest .buildFromSimplifiedDef ("type" , "only_field" ));
65+ assertEquals ("mapping source must be pairs of fieldnames and properties definition." , e .getMessage ());
66+ }
6067}
You can’t perform that action at this time.
0 commit comments