@@ -183,10 +183,14 @@ public boolean updateMapping(final IndexMetadata currentIndexMetadata, final Ind
183
183
assert newIndexMetadata .getIndex ().equals (index ()) : "index mismatch: expected " + index ()
184
184
+ " but was " + newIndexMetadata .getIndex ();
185
185
186
+ if (currentIndexMetadata != null && currentIndexMetadata .getMappingVersion () == newIndexMetadata .getMappingVersion ()) {
187
+ assertMappingVersion (currentIndexMetadata , newIndexMetadata , this .mapper );
188
+ return false ;
189
+ }
190
+
186
191
final DocumentMapper updatedMapper ;
187
192
try {
188
- // only update entries if needed
189
- updatedMapper = internalMerge (newIndexMetadata , MergeReason .MAPPING_RECOVERY , true );
193
+ updatedMapper = internalMerge (newIndexMetadata , MergeReason .MAPPING_RECOVERY );
190
194
} catch (Exception e ) {
191
195
logger .warn (() -> new ParameterizedMessage ("[{}] failed to apply mappings" , index ()), e );
192
196
throw e ;
@@ -230,7 +234,7 @@ public boolean updateMapping(final IndexMetadata currentIndexMetadata, final Ind
230
234
private void assertMappingVersion (
231
235
final IndexMetadata currentIndexMetadata ,
232
236
final IndexMetadata newIndexMetadata ,
233
- final DocumentMapper updatedMapper ) {
237
+ final DocumentMapper updatedMapper ) throws IOException {
234
238
if (Assertions .ENABLED && currentIndexMetadata != null ) {
235
239
if (currentIndexMetadata .getMappingVersion () == newIndexMetadata .getMappingVersion ()) {
236
240
// if the mapping version is unchanged, then there should not be any updates and all mappings should be the same
@@ -241,17 +245,21 @@ private void assertMappingVersion(
241
245
final CompressedXContent currentSource = currentIndexMetadata .mapping ().source ();
242
246
final CompressedXContent newSource = mapping .source ();
243
247
assert currentSource .equals (newSource ) :
244
- "expected current mapping [" + currentSource + "] for type [" + mapping .type () + "] "
245
- + "to be the same as new mapping [" + newSource + "]" ;
248
+ "expected current mapping [" + currentSource + "] for type [" + mapping .type () + "] "
249
+ + "to be the same as new mapping [" + newSource + "]" ;
250
+ final CompressedXContent mapperSource = new CompressedXContent (Strings .toString (mapper ));
251
+ assert currentSource .equals (mapperSource ) :
252
+ "expected current mapping [" + currentSource + "] for type [" + mapping .type () + "] "
253
+ + "to be the same as new mapping [" + mapperSource + "]" ;
246
254
}
247
255
248
256
} else {
249
- // if the mapping version is changed, it should increase, there should be updates, and the mapping should be different
257
+ // the mapping version should increase, there should be updates, and the mapping should be different
250
258
final long currentMappingVersion = currentIndexMetadata .getMappingVersion ();
251
259
final long newMappingVersion = newIndexMetadata .getMappingVersion ();
252
260
assert currentMappingVersion < newMappingVersion :
253
- "expected current mapping version [" + currentMappingVersion + "] "
254
- + "to be less than new mapping version [" + newMappingVersion + "]" ;
261
+ "expected current mapping version [" + currentMappingVersion + "] "
262
+ + "to be less than new mapping version [" + newMappingVersion + "]" ;
255
263
assert updatedMapper != null ;
256
264
final MappingMetadata currentMapping = currentIndexMetadata .mapping ();
257
265
if (currentMapping != null ) {
@@ -270,26 +278,18 @@ public void merge(String type, Map<String, Object> mappings, MergeReason reason)
270
278
}
271
279
272
280
public void merge (IndexMetadata indexMetadata , MergeReason reason ) {
273
- internalMerge (indexMetadata , reason , false );
281
+ internalMerge (indexMetadata , reason );
274
282
}
275
283
276
284
public DocumentMapper merge (String type , CompressedXContent mappingSource , MergeReason reason ) {
277
285
return internalMerge (type , mappingSource , reason );
278
286
}
279
287
280
- private synchronized DocumentMapper internalMerge (IndexMetadata indexMetadata ,
281
- MergeReason reason , boolean onlyUpdateIfNeeded ) {
288
+ private synchronized DocumentMapper internalMerge (IndexMetadata indexMetadata , MergeReason reason ) {
282
289
assert reason != MergeReason .MAPPING_UPDATE_PREFLIGHT ;
283
290
MappingMetadata mappingMetadata = indexMetadata .mapping ();
284
291
if (mappingMetadata != null ) {
285
- if (onlyUpdateIfNeeded ) {
286
- DocumentMapper existingMapper = documentMapper ();
287
- if (existingMapper == null || mappingMetadata .source ().equals (existingMapper .mappingSource ()) == false ) {
288
- return internalMerge (mappingMetadata .type (), mappingMetadata .source (), reason );
289
- }
290
- } else {
291
- return internalMerge (mappingMetadata .type (), mappingMetadata .source (), reason );
292
- }
292
+ return internalMerge (mappingMetadata .type (), mappingMetadata .source (), reason );
293
293
}
294
294
return null ;
295
295
}
0 commit comments