/** * Writes a "raw" (bytes) field, handling cases where the bytes are compressed, and tries to optimize writing using * {@link XContentBuilder#rawField(String, InputStream, XContentType)}. */ public static void writeRawField(String field, BytesReference source, XContentType xContentType, XContentBuilder builder, ToXContent.Params params) throws IOException { Objects.requireNonNull(xContentType); Compressor compressor = CompressorFactory.compressor(source); if (compressor != null) { try (InputStream compressedStreamInput = compressor.streamInput(source.streamInput())) { builder.rawField(field, compressedStreamInput, xContentType); } } else { try (InputStream stream = source.streamInput()) { builder.rawField(field, stream, xContentType); } } }
/** * Writes a "raw" (bytes) field, handling cases where the bytes are compressed, and tries to optimize writing using * {@link XContentBuilder#rawField(String, InputStream)}. * @deprecated use {@link #writeRawField(String, BytesReference, XContentType, XContentBuilder, Params)} to avoid content type * auto-detection */ @Deprecated public static void writeRawField(String field, BytesReference source, XContentBuilder builder, ToXContent.Params params) throws IOException { Compressor compressor = CompressorFactory.compressor(source); if (compressor != null) { try (InputStream compressedStreamInput = compressor.streamInput(source.streamInput())) { builder.rawField(field, compressedStreamInput); } } else { try (InputStream stream = source.streamInput()) { builder.rawField(field, stream); } } }
public XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(SETTINGS.getPreferredName()); settings.toXContent(builder, params); builder.endObject(); builder.startObject(MAPPINGS.getPreferredName()); for (Map.Entry<String, String> entry : mappings.entrySet()) { try (InputStream stream = new BytesArray(entry.getValue()).streamInput()) { builder.rawField(entry.getKey(), stream, XContentType.JSON); } } builder.endObject(); builder.startObject(ALIASES.getPreferredName()); for (Alias alias : aliases) { alias.toXContent(builder, params); } builder.endObject(); return builder; } }
@Override public void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(getName()); try (InputStream stream = functionBytes.streamInput()) { builder.rawField(fieldName, stream); } builder.field(DecayFunctionParser.MULTI_VALUE_MODE.getPreferredName(), multiValueMode.name()); builder.endObject(); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(name); if (filter != null) { try (InputStream stream = new BytesArray(filter).streamInput()) { builder.rawField(FILTER.getPreferredName(), stream, XContentType.JSON); } } if (indexRouting != null && indexRouting.equals(searchRouting)) { builder.field(ROUTING.getPreferredName(), indexRouting); } else { if (indexRouting != null) { builder.field(INDEX_ROUTING.getPreferredName(), indexRouting); } if (searchRouting != null) { builder.field(SEARCH_ROUTING.getPreferredName(), searchRouting); } } builder.field(IS_WRITE_INDEX.getPreferredName(), writeIndex); builder.endObject(); return builder; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field(FULL_NAME.getPreferredName(), fullName); if (params.paramAsBoolean("pretty", false)) { builder.field("mapping", sourceAsMap()); } else { try (InputStream stream = source.streamInput()) { builder.rawField(MAPPING.getPreferredName(), stream, XContentType.JSON); } } return builder; }
@Override protected XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException { if (fuzzyOptions != null) { fuzzyOptions.toXContent(builder, params); } if (regexOptions != null) { regexOptions.toXContent(builder, params); } if (skipDuplicates) { builder.field(SKIP_DUPLICATES_FIELD.getPreferredName(), skipDuplicates); } if (contextBytes != null) { try (InputStream stream = contextBytes.streamInput()) { builder.rawField(CONTEXTS_FIELD.getPreferredName(), stream); } } return builder; }
if (contentType != null && builder.contentType().mediaType().equals(contentType)) { try (InputStream stream = new BytesArray(idOrCode).streamInput()) { builder.rawField(SOURCE_PARSE_FIELD.getPreferredName(), stream);
builder.rawField(FILTER.getPreferredName(), stream, XContentType.JSON);
builder.rawField(DOC.getPreferredName(), stream, xContentType);
@Override public void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(getName()); builder.rawField(fieldName, functionBytes); builder.field(DecayFunctionParser.MULTI_VALUE_MODE.getPreferredName(), multiValueMode.name()); builder.endObject(); }
@Override public void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(getName()); try (InputStream stream = functionBytes.streamInput()) { builder.rawField(fieldName, stream); } builder.field(DecayFunctionParser.MULTI_VALUE_MODE.getPreferredName(), multiValueMode.name()); builder.endObject(); }
@Override protected XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException { if (fuzzyOptions != null) { fuzzyOptions.toXContent(builder, params); } if (regexOptions != null) { regexOptions.toXContent(builder, params); } if (contextBytes != null) { builder.rawField(CONTEXTS_FIELD.getPreferredName(), contextBytes); } return builder; }
@Override public void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(getName()); try (InputStream stream = functionBytes.streamInput()) { builder.rawField(fieldName, stream); } builder.field(DecayFunctionParser.MULTI_VALUE_MODE.getPreferredName(), multiValueMode.name()); builder.endObject(); }
public NettyInteractiveResponse(String type, XContentBuilder builder) throws IOException { this.type = type; XContentBuilder responseBuilder = jsonBuilder() .startObject().field("success", true).field("type", type); if (builder != null) { responseBuilder.rawField("data", builder.bytes()); } responseBuilder.endObject(); this.response = new TextWebSocketFrame(responseBuilder.string()); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("full_name", fullName); if (params.paramAsBoolean("pretty", false)) { builder.field("mapping", sourceAsMap()); } else { builder.rawField("mapping", source, XContentType.JSON); } return builder; } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("full_name", fullName); if (params.paramAsBoolean("pretty", false)) { builder.field("mapping", sourceAsMap()); } else { builder.rawField("mapping", source); } return builder; } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field(FULL_NAME.getPreferredName(), fullName); if (params.paramAsBoolean("pretty", false)) { builder.field("mapping", sourceAsMap()); } else { try (InputStream stream = source.streamInput()) { builder.rawField(MAPPING.getPreferredName(), stream, XContentType.JSON); } } return builder; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field(FULL_NAME.getPreferredName(), fullName); if (params.paramAsBoolean("pretty", false)) { builder.field("mapping", sourceAsMap()); } else { try (InputStream stream = source.streamInput()) { builder.rawField(MAPPING.getPreferredName(), stream, XContentType.JSON); } } return builder; }
@Override protected XContentBuilder scriptFieldToXContent(String template, ScriptType type, XContentBuilder builder, Params builderParams) throws IOException { if (type == ScriptType.INLINE && contentType != null && builder.contentType() == contentType) { builder.rawField(type.getParseField().getPreferredName(), new BytesArray(template)); } else { builder.field(type.getParseField().getPreferredName(), template); } return builder; }