/** * The template source definition. */ public PutIndexTemplateRequest source(XContentBuilder templateBuilder) { try { return source(BytesReference.bytes(templateBuilder), templateBuilder.contentType()); } catch (Exception e) { throw new IllegalArgumentException("Failed to build json for template request", e); } }
/** * Creates a new response based on {@link XContentBuilder}. */ public BytesRestResponse(RestStatus status, XContentBuilder builder) { this(status, builder.contentType().mediaType(), BytesReference.bytes(builder)); }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source */ public CreateIndexRequest mapping(String type, XContentBuilder source) { return mapping(type, BytesReference.bytes(source), source.contentType()); }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source */ public PutIndexTemplateRequest mapping(String type, XContentBuilder source) { return mapping(type, BytesReference.bytes(source), source.contentType()); }
/** * Sets the settings and mappings as a single source. */ public CreateIndexRequest source(XContentBuilder source) { return source(BytesReference.bytes(source), source.contentType()); }
/** * Sets the content source to index. */ public IndexRequest source(XContentBuilder sourceBuilder) { return source(BytesReference.bytes(sourceBuilder), sourceBuilder.contentType()); }
/** * Sets an artificial document from which term vectors are requested for. */ public TermVectorsRequest doc(XContentBuilder documentBuilder) { return this.doc(BytesReference.bytes(documentBuilder), true, documentBuilder.contentType()); }
/** * The mapping source definition. */ public PutMappingRequest source(XContentBuilder mappingBuilder) { return source(Strings.toString(mappingBuilder), mappingBuilder.contentType()); }
/** * Allows to set the settings using a json builder. */ public CreateIndexRequest settings(XContentBuilder builder) { settings(Strings.toString(builder), builder.contentType()); return this; }
/** * Constructor for an artificial document request, that is not present in the index. * * @param index the index to be used for parsing the doc * @param type the type to be used for parsing the doc * @param doc the document specification */ public Item(@Nullable String index, @Nullable String type, XContentBuilder doc) { if (doc == null) { throw new IllegalArgumentException("Item requires doc to be non-null"); } this.index = index; this.type = type; this.doc = BytesReference.bytes(doc); this.xContentType = doc.contentType(); }
NameOrDefinition(Map<String, ?> definition) { this.name = null; Objects.requireNonNull(definition); try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(definition); this.definition = Settings.builder().loadFromSource(Strings.toString(builder), builder.contentType()).build(); } catch (IOException e) { throw new IllegalArgumentException("Failed to parse [" + definition + "]", e); } }
public BytesRestResponse(RestChannel channel, RestStatus status, Exception e) throws IOException { this.status = status; try (XContentBuilder builder = build(channel, status, e)) { this.content = BytesReference.bytes(builder); this.contentType = builder.contentType().mediaType(); } if (e instanceof ElasticsearchException) { copyHeaders(((ElasticsearchException) e)); } }
/** * Sets settings that should be added/changed in all restored indices */ public RestoreSnapshotRequest indexSettings(Map<String, Object> source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); indexSettings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
/** * Sets the settings to be updated (either json or yaml format) */ @SuppressWarnings("unchecked") public UpdateSettingsRequest settings(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); settings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
/** * Sets the persistent settings to be updated. They will get applied cross restarts */ @SuppressWarnings({"unchecked", "rawtypes"}) public ClusterUpdateSettingsRequest persistentSettings(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); persistentSettings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
/** * Sets the transient settings to be updated. They will not survive a full cluster restart */ @SuppressWarnings({"unchecked", "rawtypes"}) public ClusterUpdateSettingsRequest transientSettings(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); transientSettings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
/** * Sets the repository settings. * * @param source repository settings * @return this request */ public PutRepositoryRequest settings(Map<String, Object> source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); settings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
/** * Sets repository-specific snapshot settings. * <p> * See repository documentation for more information. * * @param source repository-specific snapshot settings * @return this request */ public CreateSnapshotRequest settings(Map<String, Object> source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); settings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { boolean includeDefaults = params.paramAsBoolean("include_defaults", false); if (!includeDefaults) { // simulate the generation to make sure we don't add unnecessary content if all is default // if all are defaults, no need to write it at all - generating is twice is ok though BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(0); XContentBuilder b = new XContentBuilder(builder.contentType().xContent(), bytesStreamOutput); b.startObject().flush(); long pos = bytesStreamOutput.position(); innerToXContent(b, false); b.flush(); if (pos == bytesStreamOutput.position()) { return builder; } } builder.startObject(CONTENT_TYPE); innerToXContent(builder, includeDefaults); builder.endObject(); return builder; }
/** * Sets repository-specific restore settings * <p> * See repository documentation for more information. * * @param source repository-specific snapshot settings * @return this request */ public RestoreSnapshotRequest settings(Map<String, Object> source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); settings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }