diff --git a/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/cbor/CborXContentImpl.java b/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/cbor/CborXContentImpl.java index 2a8e7a4dfa12c..3aa8323eb5495 100644 --- a/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/cbor/CborXContentImpl.java +++ b/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/cbor/CborXContentImpl.java @@ -63,8 +63,8 @@ public XContentType type() { } @Override - public byte streamSeparator() { - throw new XContentParseException("cbor does not support stream parsing..."); + public byte bulkSeparator() { + throw new XContentParseException("cbor does not support bulk parsing..."); } @Override diff --git a/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/JsonXContentImpl.java b/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/JsonXContentImpl.java index 2e4925b4a853e..ae494796c88cb 100644 --- a/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/JsonXContentImpl.java +++ b/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/JsonXContentImpl.java @@ -65,7 +65,7 @@ public XContentType type() { } @Override - public byte streamSeparator() { + public byte bulkSeparator() { return '\n'; } diff --git a/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/smile/SmileXContentImpl.java b/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/smile/SmileXContentImpl.java index 3c774c582c638..83528980c2b52 100644 --- a/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/smile/SmileXContentImpl.java +++ b/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/smile/SmileXContentImpl.java @@ -65,7 +65,7 @@ public XContentType type() { } @Override - public byte streamSeparator() { + public byte bulkSeparator() { return (byte) 0xFF; } diff --git a/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/yaml/YamlXContentImpl.java b/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/yaml/YamlXContentImpl.java index 6a22508ba51c6..6e1496bfffd7b 100644 --- a/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/yaml/YamlXContentImpl.java +++ b/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/yaml/YamlXContentImpl.java @@ -61,8 +61,8 @@ public XContentType type() { } @Override - public byte streamSeparator() { - throw new UnsupportedOperationException("yaml does not support stream parsing..."); + public byte bulkSeparator() { + throw new UnsupportedOperationException("yaml does not support bulk parsing..."); } @Override diff --git a/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContent.java b/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContent.java index 146f90b8e2510..56eb308eaebae 100644 --- a/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContent.java +++ b/libs/x-content/src/main/java/org/elasticsearch/xcontent/XContent.java @@ -24,7 +24,7 @@ public interface XContent { */ XContentType type(); - byte streamSeparator(); + byte bulkSeparator(); @Deprecated boolean detectContent(byte[] bytes, int offset, int length); diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java index b97d1b00573f4..2e50d14b24d72 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java @@ -142,12 +142,12 @@ public static byte[] writeMultiLineFormat(MultiSearchTemplateRequest multiSearch MultiSearchRequest.writeSearchRequestParams(searchRequest, xContentBuilder); BytesReference.bytes(xContentBuilder).writeTo(output); } - output.write(xContent.streamSeparator()); + output.write(xContent.bulkSeparator()); try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) { templateRequest.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS); BytesReference.bytes(xContentBuilder).writeTo(output); } - output.write(xContent.streamSeparator()); + output.write(xContent.bulkSeparator()); } return output.toByteArray(); } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java index d9466536ac46c..f7f68324907ff 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java @@ -94,7 +94,7 @@ public static MultiSearchTemplateRequest parseRequest(RestRequest restRequest, b } @Override - public boolean supportsContentStream() { + public boolean supportsBulkContent() { return true; } diff --git a/server/src/main/java/org/elasticsearch/action/bulk/BulkRequestParser.java b/server/src/main/java/org/elasticsearch/action/bulk/BulkRequestParser.java index 75ab08de942dc..898bfd0e1652c 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/BulkRequestParser.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/BulkRequestParser.java @@ -139,7 +139,7 @@ public void parse( XContent xContent = xContentType.xContent(); int line = 0; int from = 0; - byte marker = xContent.streamSeparator(); + byte marker = xContent.bulkSeparator(); // Bulk requests can contain a lot of repeated strings for the index, pipeline and routing parameters. This map is used to // deduplicate duplicate strings parsed for these parameters. While it does not prevent instantiating the duplicate strings, it // reduces their lifetime to the lifetime of this parse call instead of the lifetime of the full bulk request. diff --git a/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java b/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java index 4bf8206861a4d..fa22cb36b70ab 100644 --- a/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java +++ b/server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java @@ -206,7 +206,7 @@ public static void readMultiLineFormat( TriFunction extraParamParser ) throws IOException { int from = 0; - byte marker = xContent.streamSeparator(); + byte marker = xContent.bulkSeparator(); while (true) { int nextMarker = findNextMarker(marker, from, data); if (nextMarker == -1) { @@ -343,7 +343,7 @@ public static byte[] writeMultiLineFormat(MultiSearchRequest multiSearchRequest, writeSearchRequestParams(request, xContentBuilder); BytesReference.bytes(xContentBuilder).writeTo(output); } - output.write(xContent.streamSeparator()); + output.write(xContent.bulkSeparator()); try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) { if (request.source() != null) { request.source().toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS); @@ -353,7 +353,7 @@ public static byte[] writeMultiLineFormat(MultiSearchRequest multiSearchRequest, } BytesReference.bytes(xContentBuilder).writeTo(output); } - output.write(xContent.streamSeparator()); + output.write(xContent.bulkSeparator()); } return output.toByteArray(); } diff --git a/server/src/main/java/org/elasticsearch/rest/FilterRestHandler.java b/server/src/main/java/org/elasticsearch/rest/FilterRestHandler.java index a3b3c9d7b17f1..e07d8aad04609 100644 --- a/server/src/main/java/org/elasticsearch/rest/FilterRestHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/FilterRestHandler.java @@ -48,8 +48,8 @@ public boolean allowsUnsafeBuffers() { } @Override - public boolean supportsContentStream() { - return delegate.supportsContentStream(); + public boolean supportsBulkContent() { + return delegate.supportsBulkContent(); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/RestController.java b/server/src/main/java/org/elasticsearch/rest/RestController.java index 3f9c0dbaa11d6..8592888d2dd03 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestController.java +++ b/server/src/main/java/org/elasticsearch/rest/RestController.java @@ -432,7 +432,7 @@ private void dispatchRequest( } final XContentType xContentType = request.getXContentType(); // TODO consider refactoring to handler.supportsContentStream(xContentType). It is only used with JSON and SMILE - if (handler.supportsContentStream() + if (handler.supportsBulkContent() && XContentType.JSON != xContentType.canonical() && XContentType.SMILE != xContentType.canonical()) { channel.sendResponse( diff --git a/server/src/main/java/org/elasticsearch/rest/RestHandler.java b/server/src/main/java/org/elasticsearch/rest/RestHandler.java index 11208a24ceb10..474bf02b4b92b 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/RestHandler.java @@ -39,11 +39,11 @@ default boolean canTripCircuitBreaker() { } /** - * Indicates if the RestHandler supports content as a stream. A stream would be multiple objects delineated by - * {@link XContent#streamSeparator()}. If a handler returns true this will affect the types of content that can be sent to - * this endpoint. + * Indicates if the RestHandler supports bulk content. A bulk request contains multiple objects + * delineated by {@link XContent#bulkSeparator()}. If a handler returns true this will affect + * the types of content that can be sent to this endpoint. */ - default boolean supportsContentStream() { + default boolean supportsBulkContent() { return false; } diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java index 0bb97b1f51ff5..d213d4410c07c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java @@ -101,7 +101,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC } @Override - public boolean supportsContentStream() { + public boolean supportsBulkContent() { return true; } diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index 0a7a4a9701a90..d45cbaecb5a62 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -209,7 +209,7 @@ public static void parseMultiLineRequest( } @Override - public boolean supportsContentStream() { + public boolean supportsBulkContent() { return true; } diff --git a/server/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java b/server/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java index 5732e7f29f65d..61f5105301c30 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java @@ -290,13 +290,13 @@ public void testSmileIsSupported() throws IOException { builder.endObject(); builder.endObject(); } - out.write(xContentType.xContent().streamSeparator()); + out.write(xContentType.xContent().bulkSeparator()); try (XContentBuilder builder = XContentFactory.contentBuilder(xContentType, out)) { builder.startObject(); builder.field("field", "value"); builder.endObject(); } - out.write(xContentType.xContent().streamSeparator()); + out.write(xContentType.xContent().bulkSeparator()); data = out.bytes(); } @@ -327,7 +327,7 @@ public void testToValidateUpsertRequestAndCASInBulkRequest() throws IOException builder.endObject(); builder.endObject(); } - out.write(xContentType.xContent().streamSeparator()); + out.write(xContentType.xContent().bulkSeparator()); try (XContentBuilder builder = XContentFactory.contentBuilder(xContentType, out)) { builder.startObject(); builder.startObject("doc").endObject(); @@ -338,7 +338,7 @@ public void testToValidateUpsertRequestAndCASInBulkRequest() throws IOException builder.field("upsert", values); builder.endObject(); } - out.write(xContentType.xContent().streamSeparator()); + out.write(xContentType.xContent().bulkSeparator()); data = out.bytes(); } BulkRequest bulkRequest = new BulkRequest(); diff --git a/server/src/test/java/org/elasticsearch/rest/DeprecationRestHandlerTests.java b/server/src/test/java/org/elasticsearch/rest/DeprecationRestHandlerTests.java index 90d9f1bcac879..a1898082418e5 100644 --- a/server/src/test/java/org/elasticsearch/rest/DeprecationRestHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/rest/DeprecationRestHandlerTests.java @@ -155,17 +155,17 @@ public void testInvalidHeaderValueEmpty() { expectThrows(IllegalArgumentException.class, () -> DeprecationRestHandler.requireValidHeader(blank)); } - public void testSupportsContentStreamTrue() { - when(handler.supportsContentStream()).thenReturn(true); + public void testSupportsBulkContentTrue() { + when(handler.supportsBulkContent()).thenReturn(true); assertTrue( - new DeprecationRestHandler(handler, METHOD, PATH, null, deprecationMessage, deprecationLogger, false).supportsContentStream() + new DeprecationRestHandler(handler, METHOD, PATH, null, deprecationMessage, deprecationLogger, false).supportsBulkContent() ); } - public void testSupportsContentStreamFalse() { - when(handler.supportsContentStream()).thenReturn(false); + public void testSupportsBulkContentFalse() { + when(handler.supportsBulkContent()).thenReturn(false); assertFalse( - new DeprecationRestHandler(handler, METHOD, PATH, null, deprecationMessage, deprecationLogger, false).supportsContentStream() + new DeprecationRestHandler(handler, METHOD, PATH, null, deprecationMessage, deprecationLogger, false).supportsBulkContent() ); } diff --git a/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java b/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java index 67f42e6cf1808..391b2a08021fd 100644 --- a/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java +++ b/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java @@ -598,7 +598,7 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c } @Override - public boolean supportsContentStream() { + public boolean supportsBulkContent() { return true; } }); @@ -637,7 +637,7 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c } @Override - public boolean supportsContentStream() { + public boolean supportsBulkContent() { return true; } }); @@ -662,7 +662,7 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c } @Override - public boolean supportsContentStream() { + public boolean supportsBulkContent() { return true; } }); @@ -688,7 +688,7 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c } @Override - public boolean supportsContentStream() { + public boolean supportsBulkContent() { return true; } }); @@ -713,7 +713,7 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c } @Override - public boolean supportsContentStream() { + public boolean supportsBulkContent() { return true; } }); diff --git a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java index d13fd2f347f7b..1f4a4dcf9dbfa 100644 --- a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java +++ b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java @@ -200,7 +200,7 @@ private HttpEntity createEntity(List> bodies, Map indexRequests = new ArrayList<>(); new BulkRequestParser(false, RestApiVersion.current()).parse(