Skip to content

Commit

Permalink
force the type to be set when using the put mapping API in Java
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed May 31, 2011
1 parent 198b219 commit 8267a76
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8267a76

Please sign in to comment.