force the type to be set when using the put mapping API in Java
This commit is contained in:
parent
198b219baf
commit
8267a76747
|
@ -76,6 +76,9 @@ public class PutMappingRequest extends MasterNodeOperationRequest {
|
|||
|
||||
@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 class PutMappingRequest extends MasterNodeOperationRequest {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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.PutMappingRequest;
|
|||
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 class PutMappingRequestBuilder extends BaseIndicesRequestBuilder<PutMappi
|
|||
}
|
||||
|
||||
/**
|
||||
* 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.action.count.CountResponse;
|
|||
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 @@ public class SimpleAttachmentIntegrationTests {
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue