21
21
22
22
import com .carrotsearch .hppc .ObjectHashSet ;
23
23
import org .elasticsearch .ElasticsearchGenerationException ;
24
+ import org .elasticsearch .Version ;
24
25
import org .elasticsearch .action .ActionRequestValidationException ;
25
26
import org .elasticsearch .action .IndicesRequest ;
26
27
import org .elasticsearch .action .support .IndicesOptions ;
37
38
import org .elasticsearch .common .xcontent .XContentHelper ;
38
39
import org .elasticsearch .common .xcontent .XContentType ;
39
40
import org .elasticsearch .index .Index ;
41
+ import org .elasticsearch .index .mapper .MapperService ;
40
42
41
43
import java .io .IOException ;
42
44
import java .io .InputStream ;
48
50
import static org .elasticsearch .action .ValidateActions .addValidationError ;
49
51
50
52
/**
51
- * Puts mapping definition registered under a specific type into one or more indices. Best created with
53
+ * Puts mapping definition into one or more indices. Best created with
52
54
* {@link org.elasticsearch.client.Requests#putMappingRequest(String...)}.
53
55
* <p>
54
56
* If the mappings already exists, the new mappings will be merged with the new one. If there are elements
@@ -69,8 +71,6 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
69
71
70
72
private IndicesOptions indicesOptions = IndicesOptions .fromOptions (false , false , true , true );
71
73
72
- private String type ;
73
-
74
74
private String source ;
75
75
private String origin = "" ;
76
76
@@ -80,7 +80,12 @@ public PutMappingRequest(StreamInput in) throws IOException {
80
80
super (in );
81
81
indices = in .readStringArray ();
82
82
indicesOptions = IndicesOptions .readIndicesOptions (in );
83
- type = in .readOptionalString ();
83
+ if (in .getVersion ().before (Version .V_8_0_0 )) {
84
+ String type = in .readOptionalString ();
85
+ if (MapperService .SINGLE_MAPPING_NAME .equals (type ) == false ) {
86
+ throw new IllegalArgumentException ("Expected type [_doc] but received [" + type + "]" );
87
+ }
88
+ }
84
89
source = in .readString ();
85
90
concreteIndex = in .readOptionalWriteable (Index ::new );
86
91
origin = in .readOptionalString ();
@@ -100,11 +105,6 @@ public PutMappingRequest(String... indices) {
100
105
@ Override
101
106
public ActionRequestValidationException validate () {
102
107
ActionRequestValidationException validationException = null ;
103
- if (type == null ) {
104
- validationException = addValidationError ("mapping type is missing" , validationException );
105
- }else if (type .isEmpty ()) {
106
- validationException = addValidationError ("mapping type is empty" , validationException );
107
- }
108
108
if (source == null ) {
109
109
validationException = addValidationError ("mapping source is missing" , validationException );
110
110
} else if (source .isEmpty ()) {
@@ -160,21 +160,6 @@ public PutMappingRequest indicesOptions(IndicesOptions indicesOptions) {
160
160
return this ;
161
161
}
162
162
163
- /**
164
- * The mapping type.
165
- */
166
- public String type () {
167
- return type ;
168
- }
169
-
170
- /**
171
- * The type of the mappings.
172
- */
173
- public PutMappingRequest type (String type ) {
174
- this .type = type ;
175
- return this ;
176
- }
177
-
178
163
/**
179
164
* The mapping source definition.
180
165
*/
@@ -190,7 +175,7 @@ public String source() {
190
175
* mapping fields will automatically be put on the top level mapping object.
191
176
*/
192
177
public PutMappingRequest source (Object ... source ) {
193
- return source (buildFromSimplifiedDef (type , source ));
178
+ return source (buildFromSimplifiedDef (MapperService . SINGLE_MAPPING_NAME , source ));
194
179
}
195
180
196
181
public String origin () {
@@ -314,7 +299,9 @@ public void writeTo(StreamOutput out) throws IOException {
314
299
super .writeTo (out );
315
300
out .writeStringArrayNullable (indices );
316
301
indicesOptions .writeIndicesOptions (out );
317
- out .writeOptionalString (type );
302
+ if (out .getVersion ().before (Version .V_8_0_0 )) {
303
+ out .writeOptionalString (MapperService .SINGLE_MAPPING_NAME );
304
+ }
318
305
out .writeString (source );
319
306
out .writeOptionalWriteable (concreteIndex );
320
307
out .writeOptionalString (origin );
0 commit comments