diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ObjectMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ObjectMapper.java index d154a937a52..44da3130a10 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ObjectMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ObjectMapper.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import static org.elasticsearch.common.collect.ImmutableMap.*; import static org.elasticsearch.common.collect.Lists.*; @@ -575,8 +576,11 @@ public class ObjectMapper implements XContentMapper, IncludeInAllMapper { doXContent(builder, params); + // sort the mappers so we get consistent serialization format + TreeMap sortedMappers = new TreeMap(mappers); + // check internal mappers first (this is only relevant for root object) - for (XContentMapper mapper : mappers.values()) { + for (XContentMapper mapper : sortedMappers.values()) { if (mapper instanceof InternalMapper) { mapper.toXContent(builder, params); } @@ -589,7 +593,7 @@ public class ObjectMapper implements XContentMapper, IncludeInAllMapper { if (!mappers.isEmpty()) { builder.startObject("properties"); - for (XContentMapper mapper : mappers.values()) { + for (XContentMapper mapper : sortedMappers.values()) { if (!(mapper instanceof InternalMapper)) { mapper.toXContent(builder, params); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index a71dcd33f18..d6c9e486c75 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -276,9 +276,9 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent