Skip to content

Commit eda3579

Browse files
committed
force the type to be set when using the put mapping API in Java
1 parent 07a394a commit eda3579

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public PutMappingRequest(String... indices) {
7676

7777
@Override public ActionRequestValidationException validate() {
7878
ActionRequestValidationException validationException = null;
79+
if (mappingType == null) {
80+
validationException = addValidationError("mapping type is missing", validationException);
81+
}
7982
if (mappingSource == null) {
8083
validationException = addValidationError("mapping source is missing", validationException);
8184
}
@@ -105,10 +108,9 @@ public String type() {
105108
}
106109

107110
/**
108-
* The type of the mappings. Not required since it can be defined explicitly within the mapping source.
109-
* If it is not defined within the mapping source, then it is required.
111+
* The type of the mappings.
110112
*/
111-
public PutMappingRequest type(String mappingType) {
113+
@Required public PutMappingRequest type(String mappingType) {
112114
this.mappingType = mappingType;
113115
return this;
114116
}

modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/mapping/put/PutMappingRequestBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
2525
import org.elasticsearch.client.IndicesAdminClient;
2626
import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder;
27+
import org.elasticsearch.common.Required;
2728
import org.elasticsearch.common.unit.TimeValue;
2829
import org.elasticsearch.common.xcontent.XContentBuilder;
2930

@@ -44,10 +45,9 @@ public PutMappingRequestBuilder setIndices(String... indices) {
4445
}
4546

4647
/**
47-
* The type of the mappings. Not required since it can be defined explicitly within the mapping source.
48-
* If it is not defined within the mapping source, then it is required.
48+
* The type of the mappings.
4949
*/
50-
public PutMappingRequestBuilder setType(String type) {
50+
@Required public PutMappingRequestBuilder setType(String type) {
5151
request.type(type);
5252
return this;
5353
}

plugins/mapper/attachments/src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
import org.elasticsearch.common.logging.ESLogger;
2626
import org.elasticsearch.common.logging.Loggers;
2727
import org.elasticsearch.node.Node;
28-
import org.testng.annotations.*;
28+
import org.testng.annotations.AfterClass;
29+
import org.testng.annotations.AfterMethod;
30+
import org.testng.annotations.BeforeClass;
31+
import org.testng.annotations.BeforeMethod;
32+
import org.testng.annotations.Test;
2933

3034
import static org.elasticsearch.client.Requests.*;
3135
import static org.elasticsearch.common.io.Streams.*;
@@ -73,7 +77,7 @@ public class SimpleAttachmentIntegrationTests {
7377
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
7478
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testXHTML.html");
7579

76-
node.client().admin().indices().putMapping(putMappingRequest("test").source(mapping)).actionGet();
80+
node.client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
7781

7882
node.client().index(indexRequest("test").type("person")
7983
.source(jsonBuilder().startObject().field("file", html).endObject())).actionGet();

0 commit comments

Comments
 (0)