@@ -117,34 +117,25 @@ public void testConflictSameType() throws Exception {
117
117
}
118
118
119
119
public void testConflictNewType () throws Exception {
120
- XContentBuilder mapping = XContentFactory .jsonBuilder ().startObject ().startObject ("type1 " )
120
+ XContentBuilder mapping = XContentFactory .jsonBuilder ().startObject ().startObject ("type " )
121
121
.startObject ("properties" ).startObject ("foo" ).field ("type" , "long" ).endObject ()
122
122
.endObject ().endObject ().endObject ();
123
- MapperService mapperService = createIndex ("test" , Settings .builder ().build (), "type1 " , mapping ).mapperService ();
123
+ MapperService mapperService = createIndex ("test" , Settings .builder ().build (), "type " , mapping ).mapperService ();
124
124
125
- XContentBuilder update = XContentFactory .jsonBuilder ().startObject ().startObject ("type2 " )
125
+ XContentBuilder update = XContentFactory .jsonBuilder ().startObject ().startObject ("type " )
126
126
.startObject ("properties" ).startObject ("foo" ).field ("type" , "double" ).endObject ()
127
127
.endObject ().endObject ().endObject ();
128
128
129
129
try {
130
- mapperService .merge ("type2" , new CompressedXContent (Strings .toString (update )), MapperService .MergeReason .MAPPING_UPDATE );
131
- fail ();
132
- } catch (IllegalArgumentException e ) {
133
- // expected
134
- assertTrue (e .getMessage (), e .getMessage ().contains ("mapper [foo] cannot be changed from type [long] to [double]" ));
135
- }
136
-
137
- try {
138
- mapperService .merge ("type2" , new CompressedXContent (Strings .toString (update )), MapperService .MergeReason .MAPPING_UPDATE );
130
+ mapperService .merge ("type" , new CompressedXContent (Strings .toString (update )), MapperService .MergeReason .MAPPING_UPDATE );
139
131
fail ();
140
132
} catch (IllegalArgumentException e ) {
141
133
// expected
142
134
assertTrue (e .getMessage (), e .getMessage ().contains ("mapper [foo] cannot be changed from type [long] to [double]" ));
143
135
}
144
136
145
- assertThat (((FieldMapper ) mapperService .documentMapper ("type1 " ).mapping ().root ().getMapper ("foo" )).fieldType ().typeName (),
137
+ assertThat (((FieldMapper ) mapperService .documentMapper ("type " ).mapping ().root ().getMapper ("foo" )).fieldType ().typeName (),
146
138
equalTo ("long" ));
147
- assertNull (mapperService .documentMapper ("type2" ));
148
139
}
149
140
150
141
// same as the testConflictNewType except that the mapping update is on an existing type
@@ -208,15 +199,15 @@ public void testReuseMetaField() throws IOException {
208
199
209
200
public void testRejectFieldDefinedTwice () throws IOException {
210
201
String mapping1 = Strings .toString (XContentFactory .jsonBuilder ().startObject ()
211
- .startObject ("type1 " )
202
+ .startObject ("type " )
212
203
.startObject ("properties" )
213
204
.startObject ("foo" )
214
205
.field ("type" , "object" )
215
206
.endObject ()
216
207
.endObject ()
217
208
.endObject ().endObject ());
218
209
String mapping2 = Strings .toString (XContentFactory .jsonBuilder ().startObject ()
219
- .startObject ("type2 " )
210
+ .startObject ("type " )
220
211
.startObject ("properties" )
221
212
.startObject ("foo" )
222
213
.field ("type" , "long" )
@@ -225,17 +216,15 @@ public void testRejectFieldDefinedTwice() throws IOException {
225
216
.endObject ().endObject ());
226
217
227
218
MapperService mapperService1 = createIndex ("test1" ).mapperService ();
228
- mapperService1 .merge ("type1 " , new CompressedXContent (mapping1 ), MergeReason .MAPPING_UPDATE );
219
+ mapperService1 .merge ("type " , new CompressedXContent (mapping1 ), MergeReason .MAPPING_UPDATE );
229
220
IllegalArgumentException e = expectThrows (IllegalArgumentException .class ,
230
- () -> mapperService1 .merge ("type2" , new CompressedXContent (mapping2 ), MergeReason .MAPPING_UPDATE ));
231
- assertThat (e .getMessage (), equalTo ("[foo] is defined as a field in mapping [type2"
232
- + "] but this name is already used for an object in other types" ));
221
+ () -> mapperService1 .merge ("type" , new CompressedXContent (mapping2 ), MergeReason .MAPPING_UPDATE ));
222
+ assertThat (e .getMessage (), equalTo ("Can't merge a non object mapping [foo] with an object mapping [foo]" ));
233
223
234
224
MapperService mapperService2 = createIndex ("test2" ).mapperService ();
235
- mapperService2 .merge ("type2 " , new CompressedXContent (mapping2 ), MergeReason .MAPPING_UPDATE );
225
+ mapperService2 .merge ("type " , new CompressedXContent (mapping2 ), MergeReason .MAPPING_UPDATE );
236
226
e = expectThrows (IllegalArgumentException .class ,
237
- () -> mapperService2 .merge ("type1" , new CompressedXContent (mapping1 ), MergeReason .MAPPING_UPDATE ));
238
- assertThat (e .getMessage (), equalTo ("[foo] is defined as an object in mapping [type1"
239
- + "] but this name is already used for a field in other types" ));
227
+ () -> mapperService2 .merge ("type" , new CompressedXContent (mapping1 ), MergeReason .MAPPING_UPDATE ));
228
+ assertThat (e .getMessage (), equalTo ("mapper [foo] of different type, current_type [long], merged_type [ObjectMapper]" ));
240
229
}
241
230
}
0 commit comments