private XContentBuilder generateSource(long id, Random random) throws IOException { int contentLength = RandomNumbers.randomIntBetween(random, minFieldSize, maxFieldSize); StringBuilder text = new StringBuilder(contentLength); while (text.length() < contentLength) { int tokenLength = RandomNumbers.randomIntBetween(random, 1, Math.min(contentLength - text.length(), 10)); text.append(" ").append(RandomStrings.randomRealisticUnicodeOfCodepointLength(random, tokenLength)); } XContentBuilder builder = XContentFactory.smileBuilder(); builder.startObject().field("test", "value" + id) .field("text", text.toString()) .field("id", id) .endObject(); return builder; }
@Override public IndexWarmersMetaData fromMap(Map<String, Object> map) throws IOException { // if it starts with the type, remove it if (map.size() == 1 && map.containsKey(TYPE)) { map = (Map<String, Object>) map.values().iterator().next(); } XContentBuilder builder = XContentFactory.smileBuilder().map(map); try (XContentParser parser = XContentFactory.xContent(XContentType.SMILE).createParser(builder.bytes())) { // move to START_OBJECT parser.nextToken(); return fromXContent(parser); } }
/** * Constructs a xcontent builder that will output the result into the provided output stream. */ public static XContentBuilder contentBuilder(XContentType type, OutputStream outputStream) throws IOException { if (type == XContentType.JSON) { return jsonBuilder(outputStream); } else if (type == XContentType.SMILE) { return smileBuilder(outputStream); } else if (type == XContentType.YAML) { return yamlBuilder(outputStream); } else if (type == XContentType.CBOR) { return cborBuilder(outputStream); } throw new IllegalArgumentException("No matching content type for " + type); }
/** * Constructs a xcontent builder that will output the result into the provided output stream. */ public static XContentBuilder contentBuilder(XContentType type, OutputStream outputStream) throws IOException { if (type == XContentType.JSON) { return jsonBuilder(outputStream); } else if (type == XContentType.SMILE) { return smileBuilder(outputStream); } else if (type == XContentType.YAML) { return yamlBuilder(outputStream); } else if (type == XContentType.CBOR) { return cborBuilder(outputStream); } throw new IllegalArgumentException("No matching content type for " + type); }
/** * Constructs a xcontent builder that will output the result into the provided output stream. */ public static XContentBuilder contentBuilder(XContentType type, OutputStream outputStream) throws IOException { if (type == XContentType.JSON) { return jsonBuilder(outputStream); } else if (type == XContentType.SMILE) { return smileBuilder(outputStream); } else if (type == XContentType.YAML) { return yamlBuilder(outputStream); } else if (type == XContentType.CBOR) { return cborBuilder(outputStream); } throw new IllegalArgumentException("No matching content type for " + type); }
/** * Constructs a xcontent builder that will output the result into the provided output stream. */ public static XContentBuilder contentBuilder(XContentType type, OutputStream outputStream) throws IOException { if (type == XContentType.JSON) { return jsonBuilder(outputStream); } else if (type == XContentType.SMILE) { return smileBuilder(outputStream); } else if (type == XContentType.YAML) { return yamlBuilder(outputStream); } else if (type == XContentType.CBOR) { return cborBuilder(outputStream); } throw new IllegalArgumentException("No matching content type for " + type); }
/** * "Freeze" the parsing content, which means copying the current parser's * structure into an internal {@link BytesReference} to be parsed later. * @return the original XContentStructure object */ public XContentStructure freeze() throws IOException { this.bytes(XContentFactory.smileBuilder().copyCurrentStructure(parseContext.parser()).bytes()); return this; }
public void query() throws IOException { if (path != null) { setPathLevel(); try { innerQuery = parseContext.parseInnerQuery(); } finally { resetPathLevel(); } queryParsed = true; } else { source = XContentFactory.smileBuilder().copyCurrentStructure(parseContext.parser()).bytes(); } queryFound = true; }
public void filter() throws IOException { if (path != null) { setPathLevel(); try { innerFilter = parseContext.parseInnerFilter(); } finally { resetPathLevel(); } filterParsed = true; } else { source = XContentFactory.smileBuilder().copyCurrentStructure(parseContext.parser()).bytes(); } filterFound = true; }
public InnerQuery(QueryParseContext parseContext1, @Nullable String... types) throws IOException { super(parseContext1); if (types != null) { String[] origTypes = QueryParseContext.setTypesWithPrevious(types); try { query = parseContext1.parseInnerQuery(); queryParsed = true; } finally { QueryParseContext.setTypes(origTypes); } } else { BytesReference innerBytes = XContentFactory.smileBuilder().copyCurrentStructure(parseContext1.parser()).bytes(); super.bytes(innerBytes); } }