diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java index 62ece236cad..d7456cafc18 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java @@ -112,7 +112,7 @@ public class GetIndexTemplatesResponseTests extends ESTestCase { assertThat(result.version(), equalTo(esIMD.version())); assertThat(esIMD.mappings().size(), equalTo(1)); - BytesArray mappingSource = new BytesArray(esIMD.mappings().valuesIt().next().uncompressed()); + BytesReference mappingSource = esIMD.mappings().valuesIt().next().uncompressed(); Map expectedMapping = XContentHelper.convertToMap(mappingSource, true, xContentBuilder.contentType()).v2(); assertThat(result.mappings().sourceAsMap(), equalTo(expectedMapping.get("_doc"))); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/AliasMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/AliasMetadata.java index b116d96f9b9..801579c79cf 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/AliasMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/AliasMetadata.java @@ -25,7 +25,6 @@ import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.cluster.Diff; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.io.stream.StreamInput; @@ -343,7 +342,7 @@ public class AliasMetadata extends AbstractDiffable implements To if (binary) { builder.field("filter", aliasMetadata.filter.compressed()); } else { - builder.field("filter", XContentHelper.convertToMap(new BytesArray(aliasMetadata.filter().uncompressed()), true).v2()); + builder.field("filter", XContentHelper.convertToMap(aliasMetadata.filter().uncompressed(), true).v2()); } } if (aliasMetadata.indexRouting() != null) { diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java b/server/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java index 2bb0a5664fd..f2a7928dc60 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java @@ -22,6 +22,7 @@ package org.elasticsearch.cluster.metadata; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentFactory; @@ -33,6 +34,7 @@ import org.elasticsearch.index.query.Rewriteable; import org.elasticsearch.indices.InvalidAliasNameException; import java.io.IOException; +import java.io.InputStream; import java.util.function.Function; import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder; @@ -125,11 +127,13 @@ public class AliasValidator { * provided {@link org.elasticsearch.index.query.QueryShardContext} * @throws IllegalArgumentException if the filter is not valid */ - public void validateAliasFilter(String alias, byte[] filter, QueryShardContext queryShardContext, - NamedXContentRegistry xContentRegistry) { + public void validateAliasFilter(String alias, BytesReference filter, QueryShardContext queryShardContext, + NamedXContentRegistry xContentRegistry) { assert queryShardContext != null; - try (XContentParser parser = XContentFactory.xContent(filter) - .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, filter)) { + + try (InputStream inputStream = filter.streamInput(); + XContentParser parser = XContentFactory.xContentType(inputStream).xContent() + .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, filter.streamInput())) { validateAliasFilter(parser, queryShardContext); } catch (Exception e) { throw new IllegalArgumentException("failed to parse filter for alias [" + alias + "]", e); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index 8e7c18e2475..5392405a105 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -35,7 +35,6 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.node.DiscoveryNodeFilters; import org.elasticsearch.cluster.routing.allocation.IndexMetadataUpdater; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.collect.ImmutableOpenIntMap; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.MapBuilder; @@ -1408,7 +1407,7 @@ public class IndexMetadata implements Diffable, ToXContentFragmen if (binary) { builder.value(cursor.value.source().compressed()); } else { - builder.map(XContentHelper.convertToMap(new BytesArray(cursor.value.source().uncompressed()), true).v2()); + builder.map(XContentHelper.convertToMap(cursor.value.source().uncompressed(), true).v2()); } } builder.endArray(); @@ -1416,7 +1415,7 @@ public class IndexMetadata implements Diffable, ToXContentFragmen builder.startObject(KEY_MAPPINGS); for (ObjectObjectCursor cursor : indexMetadata.getMappings()) { Map mapping = XContentHelper - .convertToMap(new BytesArray(cursor.value.source().uncompressed()), false).v2(); + .convertToMap(cursor.value.source().uncompressed(), false).v2(); if (mapping.size() == 1 && mapping.containsKey(cursor.key)) { // the type name is the root value, reduce it mapping = (Map) mapping.get(cursor.key); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java index d6f4f878f59..0681af22026 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java @@ -27,7 +27,6 @@ import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.cluster.Diff; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.compress.CompressedXContent; @@ -408,7 +407,7 @@ public class IndexTemplateMetadata extends AbstractDiffable cursor1 : indexTemplateMetadata.mappings()) { - Map mapping = XContentHelper.convertToMap(new BytesArray(cursor1.value.uncompressed()), false).v2(); + Map mapping = XContentHelper.convertToMap(cursor1.value.uncompressed(), false).v2(); if (mapping.size() == 1 && mapping.containsKey(cursor1.key)) { // the type name is the root value, reduce it mapping = (Map) mapping.get(cursor1.key); @@ -425,8 +424,7 @@ public class IndexTemplateMetadata extends AbstractDiffable cursor : indexTemplateMetadata.mappings()) { if (!cursor.key.equals(MapperService.DEFAULT_MAPPING)) { assert documentMapping == null; - byte[] mappingSource = cursor.value.uncompressed(); - Map mapping = XContentHelper.convertToMap(new BytesArray(mappingSource), true).v2(); + Map mapping = XContentHelper.convertToMap(cursor.value.uncompressed(), true).v2(); documentMapping = reduceMapping(cursor.key, mapping); } } @@ -439,8 +437,7 @@ public class IndexTemplateMetadata extends AbstractDiffable cursor : indexTemplateMetadata.mappings()) { - byte[] mappingSource = cursor.value.uncompressed(); - Map mapping = XContentHelper.convertToMap(new BytesArray(mappingSource), true).v2(); + Map mapping = XContentHelper.convertToMap(cursor.value.uncompressed(), true).v2(); mapping = reduceMapping(cursor.key, mapping); builder.field(cursor.key); builder.map(mapping); @@ -450,8 +447,7 @@ public class IndexTemplateMetadata extends AbstractDiffable cursor : indexTemplateMetadata.mappings()) { - byte[] data = cursor.value.uncompressed(); - builder.map(XContentHelper.convertToMap(new BytesArray(data), true).v2()); + builder.map(XContentHelper.convertToMap(cursor.value.uncompressed(), true).v2()); } builder.endArray(); } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/Template.java b/server/src/main/java/org/elasticsearch/cluster/metadata/Template.java index c4ecaa0e8f3..16a204f4042 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/Template.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/Template.java @@ -23,7 +23,6 @@ import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -169,7 +168,7 @@ public class Template extends AbstractDiffable