Fix error message for a put index template request without index_patterns (#27102)
Just correct the error message from "Validation Failed: 1: pattern is missing;" to "Validation Failed: 1: index_patterns is missing;". Closes #27100
This commit is contained in:
parent
981b7f4d39
commit
adc195e30c
|
@ -104,7 +104,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
|
|||
validationException = addValidationError("name is missing", validationException);
|
||||
}
|
||||
if (indexPatterns == null || indexPatterns.size() == 0) {
|
||||
validationException = addValidationError("pattern is missing", validationException);
|
||||
validationException = addValidationError("index patterns are missing", validationException);
|
||||
}
|
||||
return validationException;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.elasticsearch.action.admin.indices.template.put;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
|
@ -32,6 +33,11 @@ import java.util.Arrays;
|
|||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
|
||||
public class PutIndexTemplateRequestTests extends ESTestCase {
|
||||
|
||||
// bwc for #21009
|
||||
|
@ -107,4 +113,21 @@ public class PutIndexTemplateRequestTests extends ESTestCase {
|
|||
assertEquals("template", request.patterns().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
public void testValidateErrorMessage() throws Exception {
|
||||
PutIndexTemplateRequest request = new PutIndexTemplateRequest();
|
||||
ActionRequestValidationException withoutNameAndPattern = request.validate();
|
||||
assertThat(withoutNameAndPattern.getMessage(), containsString("name is missing"));
|
||||
assertThat(withoutNameAndPattern.getMessage(), containsString("index patterns are missing"));
|
||||
|
||||
request.name("foo");
|
||||
ActionRequestValidationException withoutIndexPatterns = request.validate();
|
||||
assertThat(withoutIndexPatterns.validationErrors(), hasSize(1));
|
||||
assertThat(withoutIndexPatterns.getMessage(), containsString("index patterns are missing"));
|
||||
|
||||
request.patterns(Collections.singletonList("test-*"));
|
||||
ActionRequestValidationException noError = request.validate();
|
||||
assertThat(noError, is(nullValue()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -210,3 +210,12 @@
|
|||
catch: missing
|
||||
indices.get_template:
|
||||
name: "my_template"
|
||||
|
||||
---
|
||||
"Put index template without index_patterns":
|
||||
|
||||
- do:
|
||||
catch: /index patterns are missing/
|
||||
indices.put_template:
|
||||
name: test
|
||||
body: {}
|
||||
|
|
Loading…
Reference in New Issue