Permalink
Browse files

force the type to be set when using the put mapping API in Java

  • Loading branch information...
1 parent 07a394a commit eda35792e23147f64e62f085556de532a8728fa4 @kimchy kimchy committed May 31, 2011
@@ -76,6 +76,9 @@ public PutMappingRequest(String... indices) {
@Override public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
+ if (mappingType == null) {
+ validationException = addValidationError("mapping type is missing", validationException);
+ }
if (mappingSource == null) {
validationException = addValidationError("mapping source is missing", validationException);
}
@@ -105,10 +108,9 @@ public String type() {
}
/**
- * The type of the mappings. Not required since it can be defined explicitly within the mapping source.
- * If it is not defined within the mapping source, then it is required.
+ * The type of the mappings.
*/
- public PutMappingRequest type(String mappingType) {
+ @Required public PutMappingRequest type(String mappingType) {
this.mappingType = mappingType;
return this;
}
@@ -24,6 +24,7 @@
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder;
+import org.elasticsearch.common.Required;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -44,10 +45,9 @@ public PutMappingRequestBuilder setIndices(String... indices) {
}
/**
- * The type of the mappings. Not required since it can be defined explicitly within the mapping source.
- * If it is not defined within the mapping source, then it is required.
+ * The type of the mappings.
*/
- public PutMappingRequestBuilder setType(String type) {
+ @Required public PutMappingRequestBuilder setType(String type) {
request.type(type);
return this;
}
@@ -25,7 +25,11 @@
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.node.Node;
-import org.testng.annotations.*;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.common.io.Streams.*;
@@ -73,7 +77,7 @@
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testXHTML.html");
- node.client().admin().indices().putMapping(putMappingRequest("test").source(mapping)).actionGet();
+ node.client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
node.client().index(indexRequest("test").type("person")
.source(jsonBuilder().startObject().field("file", html).endObject())).actionGet();

0 comments on commit eda3579

Please sign in to comment.