|
33 | 33 | import org.elasticsearch.common.Strings;
|
34 | 34 | import org.elasticsearch.common.bytes.BytesArray;
|
35 | 35 | import org.elasticsearch.common.bytes.BytesReference;
|
| 36 | +import org.elasticsearch.common.collect.MapBuilder; |
36 | 37 | import org.elasticsearch.common.io.stream.StreamInput;
|
37 | 38 | import org.elasticsearch.common.io.stream.StreamOutput;
|
38 | 39 | import org.elasticsearch.common.settings.Settings;
|
@@ -491,8 +492,24 @@ public void writeTo(StreamOutput out) throws IOException {
|
491 | 492 | writeSettingsToStream(settings, out);
|
492 | 493 | out.writeVInt(mappings.size());
|
493 | 494 | for (Map.Entry<String, String> entry : mappings.entrySet()) {
|
494 |
| - out.writeString(entry.getKey()); |
495 |
| - out.writeString(entry.getValue()); |
| 495 | + String type = entry.getKey(); |
| 496 | + String value = entry.getValue(); |
| 497 | + |
| 498 | + out.writeString(type); |
| 499 | + if (out.getVersion().onOrAfter(Version.V_6_6_0)) { |
| 500 | + out.writeString(value); |
| 501 | + } else { |
| 502 | + // Versions before 6.6.0 are missing a bug fix around empty mappings that are not nested under |
| 503 | + // the type name. We therefore nest them under the type name before sending them to these nodes. |
| 504 | + Map<String, Object> mappingSource = XContentHelper.convertToMap( |
| 505 | + new BytesArray(entry.getValue()), false, XContentType.JSON).v2(); |
| 506 | + if (mappingSource.size() != 1 || !mappingSource.containsKey(entry.getKey())) { |
| 507 | + mappingSource = MapBuilder.<String, Object>newMapBuilder().put(type, mappingSource).map(); |
| 508 | + } |
| 509 | + XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); |
| 510 | + builder.map(mappingSource); |
| 511 | + out.writeString(Strings.toString(builder)); |
| 512 | + } |
496 | 513 | }
|
497 | 514 | if (out.getVersion().before(Version.V_6_5_0)) {
|
498 | 515 | // Size of custom index metadata, which is removed
|
|
0 commit comments