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 implements ToXContentOb
}
if (this.mappings != null) {
Map uncompressedMapping =
- XContentHelper.convertToMap(new BytesArray(this.mappings.uncompressed()), true, XContentType.JSON).v2();
+ XContentHelper.convertToMap(this.mappings.uncompressed(), true, XContentType.JSON).v2();
if (uncompressedMapping.size() > 0) {
builder.field(MAPPINGS.getPreferredName());
builder.map(reduceMapping(uncompressedMapping));
diff --git a/server/src/main/java/org/elasticsearch/common/compress/CompressedXContent.java b/server/src/main/java/org/elasticsearch/common/compress/CompressedXContent.java
index 9a470b780cd..08f0a1d34b4 100644
--- a/server/src/main/java/org/elasticsearch/common/compress/CompressedXContent.java
+++ b/server/src/main/java/org/elasticsearch/common/compress/CompressedXContent.java
@@ -19,7 +19,6 @@
package org.elasticsearch.common.compress;
-import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.Streams;
@@ -94,13 +93,9 @@ public final class CompressedXContent {
if (compressor != null) {
// already compressed...
this.bytes = BytesReference.toBytes(data);
- this.crc32 = crc32(new BytesArray(uncompressed()));
+ this.crc32 = crc32(uncompressed());
} else {
- BytesStreamOutput out = new BytesStreamOutput();
- try (OutputStream compressedOutput = CompressorFactory.COMPRESSOR.streamOutput(out)) {
- data.writeTo(compressedOutput);
- }
- this.bytes = BytesReference.toBytes(out.bytes());
+ this.bytes = BytesReference.toBytes(CompressorFactory.COMPRESSOR.compress(data));
this.crc32 = crc32(data);
}
assertConsistent();
@@ -108,7 +103,7 @@ public final class CompressedXContent {
private void assertConsistent() {
assert CompressorFactory.compressor(new BytesArray(bytes)) != null;
- assert this.crc32 == crc32(new BytesArray(uncompressed()));
+ assert this.crc32 == crc32(uncompressed());
}
public CompressedXContent(byte[] data) throws IOException {
@@ -130,16 +125,16 @@ public final class CompressedXContent {
}
/** Return the uncompressed bytes. */
- public byte[] uncompressed() {
+ public BytesReference uncompressed() {
try {
- return BytesReference.toBytes(CompressorFactory.uncompress(new BytesArray(bytes)));
+ return CompressorFactory.uncompress(new BytesArray(bytes));
} catch (IOException e) {
throw new IllegalStateException("Cannot decompress compressed string", e);
}
}
public String string() {
- return new BytesRef(uncompressed()).utf8ToString();
+ return uncompressed().utf8ToString();
}
public static CompressedXContent readCompressedString(StreamInput in) throws IOException {
@@ -167,7 +162,7 @@ public final class CompressedXContent {
return false;
}
- return Arrays.equals(uncompressed(), that.uncompressed());
+ return uncompressed().equals(that.uncompressed());
}
@Override
diff --git a/server/src/main/java/org/elasticsearch/common/compress/Compressor.java b/server/src/main/java/org/elasticsearch/common/compress/Compressor.java
index d926a0b7dab..bb2544c7036 100644
--- a/server/src/main/java/org/elasticsearch/common/compress/Compressor.java
+++ b/server/src/main/java/org/elasticsearch/common/compress/Compressor.java
@@ -39,4 +39,20 @@ public interface Compressor {
* output. Closing the returned {@link StreamOutput} will close the provided stream output.
*/
StreamOutput streamOutput(OutputStream out) throws IOException;
+
+ /**
+ * Decompress bytes into a newly allocated buffer.
+ *
+ * @param bytesReference bytes to decompress
+ * @return decompressed bytes
+ */
+ BytesReference uncompress(BytesReference bytesReference) throws IOException;
+
+ /**
+ * Compress bytes into a newly allocated buffer.
+ *
+ * @param bytesReference bytes to compress
+ * @return compressed bytes
+ */
+ BytesReference compress(BytesReference bytesReference) throws IOException;
}
diff --git a/server/src/main/java/org/elasticsearch/common/compress/CompressorFactory.java b/server/src/main/java/org/elasticsearch/common/compress/CompressorFactory.java
index 2ff2f4e95df..013dc2d3033 100644
--- a/server/src/main/java/org/elasticsearch/common/compress/CompressorFactory.java
+++ b/server/src/main/java/org/elasticsearch/common/compress/CompressorFactory.java
@@ -21,7 +21,6 @@ package org.elasticsearch.common.compress;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference;
-import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
@@ -71,14 +70,7 @@ public class CompressorFactory {
*/
public static BytesReference uncompressIfNeeded(BytesReference bytes) throws IOException {
Compressor compressor = compressor(Objects.requireNonNull(bytes, "the BytesReference must not be null"));
- BytesReference uncompressed;
- if (compressor != null) {
- uncompressed = uncompress(bytes, compressor);
- } else {
- uncompressed = bytes;
- }
-
- return uncompressed;
+ return compressor == null ? bytes : compressor.uncompress(bytes);
}
/** Decompress the provided {@link BytesReference}. */
@@ -87,10 +79,6 @@ public class CompressorFactory {
if (compressor == null) {
throw new NotCompressedException();
}
- return uncompress(bytes, compressor);
- }
-
- private static BytesReference uncompress(BytesReference bytes, Compressor compressor) throws IOException {
- return Streams.readFully(compressor.streamInput(bytes.streamInput()));
+ return compressor.uncompress(bytes);
}
}
diff --git a/server/src/main/java/org/elasticsearch/common/compress/DeflateCompressor.java b/server/src/main/java/org/elasticsearch/common/compress/DeflateCompressor.java
index 1ba9d43ecda..8cb8084a4df 100644
--- a/server/src/main/java/org/elasticsearch/common/compress/DeflateCompressor.java
+++ b/server/src/main/java/org/elasticsearch/common/compress/DeflateCompressor.java
@@ -20,6 +20,7 @@
package org.elasticsearch.common.compress;
import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
import org.elasticsearch.common.io.stream.OutputStreamStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
@@ -36,6 +37,7 @@ import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
+import java.util.zip.InflaterOutputStream;
/**
* {@link Compressor} implementation based on the DEFLATE compression algorithm.
@@ -129,4 +131,41 @@ public class DeflateCompressor implements Compressor {
}
};
}
+
+ // Reusable Inflater reference. Note: This is not used for the decompressing stream wrapper because we don't have strong guarantees
+ // about the scope in which the stream wrapper is used.
+ private static final ThreadLocal inflaterRef = ThreadLocal.withInitial(() -> new Inflater(true));
+
+ private static final ThreadLocal baos = ThreadLocal.withInitial(BytesStreamOutput::new);
+
+ @Override
+ public BytesReference uncompress(BytesReference bytesReference) throws IOException {
+ final BytesStreamOutput buffer = baos.get();
+ final Inflater inflater = inflaterRef.get();
+ inflater.reset();
+ try (InflaterOutputStream ios = new InflaterOutputStream(buffer, inflater)) {
+ bytesReference.slice(HEADER.length, bytesReference.length() - HEADER.length).writeTo(ios);
+ }
+ final BytesReference res = buffer.copyBytes();
+ buffer.reset();
+ return res;
+ }
+
+ // Reusable Deflater reference. Note: This is not used for the compressing stream wrapper because we don't have strong guarantees
+ // about the scope in which the stream wrapper is used.
+ private static final ThreadLocal deflaterRef = ThreadLocal.withInitial(() -> new Deflater(LEVEL, true));
+
+ @Override
+ public BytesReference compress(BytesReference bytesReference) throws IOException {
+ final BytesStreamOutput buffer = baos.get();
+ final Deflater deflater = deflaterRef.get();
+ deflater.reset();
+ buffer.write(HEADER);
+ try (DeflaterOutputStream dos = new DeflaterOutputStream(buffer, deflater, true)) {
+ bytesReference.writeTo(dos);
+ }
+ final BytesReference res = buffer.copyBytes();
+ buffer.reset();
+ return res;
+ }
}
diff --git a/server/src/main/java/org/elasticsearch/indices/IndicesService.java b/server/src/main/java/org/elasticsearch/indices/IndicesService.java
index d5907af567c..8a95c8e4417 100644
--- a/server/src/main/java/org/elasticsearch/indices/IndicesService.java
+++ b/server/src/main/java/org/elasticsearch/indices/IndicesService.java
@@ -137,6 +137,7 @@ import org.elasticsearch.threadpool.ThreadPool;
import java.io.Closeable;
import java.io.IOException;
+import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.util.ArrayList;
@@ -1493,9 +1494,10 @@ public class IndicesService extends AbstractLifecycleComponent
public AliasFilter buildAliasFilter(ClusterState state, String index, Set resolvedExpressions) {
/* Being static, parseAliasFilter doesn't have access to whatever guts it needs to parse a query. Instead of passing in a bunch
* of dependencies we pass in a function that can perform the parsing. */
- CheckedFunction filterParser = bytes -> {
- try (XContentParser parser = XContentFactory.xContent(bytes)
- .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, bytes)) {
+ CheckedFunction filterParser = bytes -> {
+ try (InputStream inputStream = bytes.streamInput();
+ XContentParser parser = XContentFactory.xContentType(inputStream).xContent()
+ .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, inputStream)) {
return parseInnerQueryBuilder(parser);
}
};
diff --git a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java
index 54ecf1a09dd..2700d4ea7c6 100644
--- a/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java
+++ b/server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java
@@ -67,8 +67,6 @@ import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.compress.CompressorFactory;
import org.elasticsearch.common.compress.NotXContentException;
import org.elasticsearch.common.io.Streams;
-import org.elasticsearch.common.io.stream.BytesStreamOutput;
-import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.store.InputStreamIndexInput;
@@ -1318,12 +1316,8 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
private void cacheRepositoryData(BytesReference updated, long generation) {
if (cacheRepositoryData && bestEffortConsistency == false) {
final BytesReference serialized;
- BytesStreamOutput out = new BytesStreamOutput();
try {
- try (StreamOutput tmp = CompressorFactory.COMPRESSOR.streamOutput(out)) {
- updated.writeTo(tmp);
- }
- serialized = out.bytes();
+ serialized = CompressorFactory.COMPRESSOR.compress(updated);
final int len = serialized.length();
if (len > ByteSizeUnit.KB.toBytes(500)) {
logger.debug("Not caching repository data of size [{}] for repository [{}] because it is larger than 500KB in" +
diff --git a/server/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java b/server/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java
index 8d661dbd8b1..72d983208d7 100644
--- a/server/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java
+++ b/server/src/main/java/org/elasticsearch/search/internal/ShardSearchRequest.java
@@ -441,7 +441,7 @@ public class ShardSearchRequest extends TransportRequest implements IndicesReque
* The list of filtering aliases should be obtained by calling Metadata.filteringAliases.
* Returns {@code null} if no filtering is required.
*/
- public static QueryBuilder parseAliasFilter(CheckedFunction filterParser,
+ public static QueryBuilder parseAliasFilter(CheckedFunction filterParser,
IndexMetadata metadata, String... aliasNames) {
if (aliasNames == null || aliasNames.length == 0) {
return null;
diff --git a/server/src/test/java/org/elasticsearch/common/compress/DeflateCompressedXContentTests.java b/server/src/test/java/org/elasticsearch/common/compress/DeflateCompressedXContentTests.java
index f2c1f853e2a..42e59991d82 100644
--- a/server/src/test/java/org/elasticsearch/common/compress/DeflateCompressedXContentTests.java
+++ b/server/src/test/java/org/elasticsearch/common/compress/DeflateCompressedXContentTests.java
@@ -38,7 +38,7 @@ public class DeflateCompressedXContentTests extends ESTestCase {
private void assertEquals(CompressedXContent s1, CompressedXContent s2) {
Assert.assertEquals(s1, s2);
- assertArrayEquals(s1.uncompressed(), s2.uncompressed());
+ assertEquals(s1.uncompressed(), s2.uncompressed());
assertEquals(s1.hashCode(), s2.hashCode());
}
diff --git a/server/src/test/java/org/elasticsearch/search/internal/ShardSearchRequestTests.java b/server/src/test/java/org/elasticsearch/search/internal/ShardSearchRequestTests.java
index 6a3aa64cc04..c79aef7c0f1 100644
--- a/server/src/test/java/org/elasticsearch/search/internal/ShardSearchRequestTests.java
+++ b/server/src/test/java/org/elasticsearch/search/internal/ShardSearchRequestTests.java
@@ -24,7 +24,6 @@ import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.IndexMetadata;
-import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.compress.CompressedXContent;
@@ -44,6 +43,7 @@ import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.search.SearchSortValuesAndFormatsTests;
import java.io.IOException;
+import java.io.InputStream;
import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
@@ -188,12 +188,12 @@ public class ShardSearchRequestTests extends AbstractSearchTestCase {
}
public QueryBuilder aliasFilter(IndexMetadata indexMetadata, String... aliasNames) {
- CheckedFunction filterParser = bytes -> {
- try (XContentParser parser = XContentFactory.xContent(bytes)
- .createParser(xContentRegistry(), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes)) {
+ return ShardSearchRequest.parseAliasFilter(bytes -> {
+ try (InputStream inputStream = bytes.streamInput();
+ XContentParser parser = XContentFactory.xContentType(inputStream).xContent()
+ .createParser(xContentRegistry(), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, inputStream)) {
return parseInnerQueryBuilder(parser);
}
- };
- return ShardSearchRequest.parseAliasFilter(filterParser, indexMetadata, aliasNames);
+ }, indexMetadata, aliasNames);
}
}
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/TemplateUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/TemplateUtils.java
index 80d160e49cb..6e725d60021 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/TemplateUtils.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/TemplateUtils.java
@@ -12,7 +12,6 @@ import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.common.Strings;
-import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.compress.CompressedXContent;
@@ -167,9 +166,7 @@ public class TemplateUtils {
for (Object typeMapping : mappings.values().toArray()) {
CompressedXContent typeMappingXContent = (CompressedXContent) typeMapping;
try {
- Map typeMappingMap = convertToMap(
- new BytesArray(typeMappingXContent.uncompressed()), false,
- XContentType.JSON).v2();
+ Map typeMappingMap = convertToMap(typeMappingXContent.uncompressed(), false, XContentType.JSON).v2();
// should always contain one entry with key = typename
assert (typeMappingMap.size() == 1);
String key = typeMappingMap.keySet().iterator().next();
diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java
index 676a0b50032..2ebecea14be 100644
--- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java
+++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java
@@ -13,7 +13,6 @@ import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.service.ClusterService;
-import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.tasks.Task;
@@ -99,8 +98,7 @@ public class TransportGetRollupCapsAction extends HandledTransportAction