本文整理了Java中org.elasticsearch.common.xcontent.XContentBuilder.builder()
方法的一些代码示例,展示了XContentBuilder.builder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XContentBuilder.builder()
方法的具体详情如下:
包路径:org.elasticsearch.common.xcontent.XContentBuilder
类名称:XContentBuilder
方法名:builder
[英]Create a new XContentBuilder using the given XContent content.
The builder uses an internal BytesStreamOutput output stream to build the content.
[中]使用给定的XContent内容创建新的XContentBuilder。
构建器使用内部字节流输出流来构建内容。
代码示例来源:origin: spring-projects/spring-data-elasticsearch
DocWriteRequest.OpType opType = action.opType();
try (XContentBuilder metadata = XContentBuilder.builder(bulkContentType.xContent())) {
metadata.startObject();
try (XContentBuilder builder = XContentBuilder.builder(bulkContentType.xContent())) {
builder.copyCurrentStructure(parser);
source = BytesReference.bytes(builder).toBytesRef();
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public String toString() {
try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) {
builder.startObject();
toXContent(builder, new MapParams(Collections.singletonMap("flat_settings", "true")));
builder.endObject();
return Strings.toString(builder);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static byte[] writeMultiLineFormat(MultiSearchRequest multiSearchRequest, XContent xContent) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
for (SearchRequest request : multiSearchRequest.requests()) {
try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) {
writeSearchRequestParams(request, xContentBuilder);
BytesReference.bytes(xContentBuilder).writeTo(output);
}
output.write(xContent.streamSeparator());
try (XContentBuilder xContentBuilder = XContentBuilder.builder(xContent)) {
if (request.source() != null) {
request.source().toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
} else {
xContentBuilder.startObject();
xContentBuilder.endObject();
}
BytesReference.bytes(xContentBuilder).writeTo(output);
}
output.write(xContent.streamSeparator());
}
return output.toByteArray();
}
代码示例来源:origin: org.elasticsearch/elasticsearch
private static BytesReference parseSourceBytes(XContentParser parser) throws IOException {
try (XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent())) {
// the original document gets slightly modified: whitespaces or
// pretty printing are not preserved,
// it all depends on the current builder settings
builder.copyCurrentStructure(parser);
return BytesReference.bytes(builder);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
builder.append(System.lineSeparator());
builder.append("curl -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '");
try (XContentBuilder xContentBuilder = XContentBuilder.builder(XContentType.JSON.xContent())) {
xContentBuilder.prettyPrint();
xContentBuilder.startObject();
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Returns the bytes that represent the XContent output of the provided {@link ToXContent} object, using the provided
* {@link XContentType}. Wraps the output into a new anonymous object according to the value returned
* by the {@link ToXContent#isFragment()} method returns.
*/
public static BytesReference toXContent(ToXContent toXContent, XContentType xContentType, Params params,
boolean humanReadable) throws IOException {
try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) {
builder.humanReadable(humanReadable);
if (toXContent.isFragment()) {
builder.startObject();
}
toXContent.toXContent(builder, params);
if (toXContent.isFragment()) {
builder.endObject();
}
return BytesReference.bytes(builder);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
private static Script extractConditional(Map<String, Object> config) throws IOException {
Object scriptSource = config.remove("if");
if (scriptSource != null) {
try (XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent)
.map(normalizeScript(scriptSource));
InputStream stream = BytesReference.bytes(builder).streamInput();
XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE, stream)) {
return Script.parse(parser);
}
}
return null;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
private static String arrayToParsableString(List<String> array) {
try {
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
builder.startArray();
for (String element : array) {
builder.value(element);
}
builder.endArray();
return Strings.toString(builder);
} catch (IOException ex) {
throw new ElasticsearchException(ex);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
try (XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent())) {
代码示例来源:origin: org.elasticsearch/elasticsearch-x-content
public static XContentBuilder contentBuilder() throws IOException {
return XContentBuilder.builder(jsonXContent);
}
private static final JsonFactory jsonFactory;
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
*
* @param parser the parser for the XContent that contains the serialized GetPipelineResponse.
* @return an instance of GetPipelineResponse read from the parser
* @throws IOException If the parsing fails
*/
public static GetPipelineResponse fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
List<PipelineConfiguration> pipelines = new ArrayList<>();
while(parser.nextToken().equals(Token.FIELD_NAME)) {
String pipelineId = parser.currentName();
parser.nextToken();
XContentBuilder contentBuilder = XContentBuilder.builder(parser.contentType().xContent());
contentBuilder.generator().copyCurrentStructure(parser);
PipelineConfiguration pipeline =
new PipelineConfiguration(
pipelineId, BytesReference.bytes(contentBuilder), contentBuilder.contentType()
);
pipelines.add(pipeline);
}
ensureExpectedToken(XContentParser.Token.END_OBJECT, parser.currentToken(), parser::getTokenLocation);
return new GetPipelineResponse(pipelines);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
@Override
public String toString() {
try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) {
builder.startObject();
toXContent(builder, new MapParams(Collections.singletonMap("flat_settings", "true")));
builder.endObject();
return Strings.toString(builder);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
代码示例来源:origin: sirensolutions/siren-join
protected XContentBuilder buildSource(XContent content, Map<String, Object> map) {
try {
// Enforce the content type to be CBOR as it is more efficient for large byte arrays
return XContentBuilder.builder(XContentType.CBOR.xContent()).map(map);
}
catch (IOException e) {
logger.error("failed to build source", e);
throw new IllegalStateException("Failed to build source", e);
}
}
代码示例来源:origin: sirensolutions/siren-join
private XContentBuilder buildQuery(Map query) {
try {
if (query == null) {
return null;
}
return XContentBuilder.builder(XContentType.CBOR.xContent()).map(query);
}
catch (IOException e) {
throw new ElasticsearchParseException("Unable to build the lookup query");
}
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
private static BytesReference parseSourceBytes(XContentParser parser) throws IOException {
try (XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent())) {
// the original document gets slightly modified: whitespaces or
// pretty printing are not preserved,
// it all depends on the current builder settings
builder.copyCurrentStructure(parser);
return builder.bytes();
}
}
代码示例来源:origin: apache/servicemix-bundles
private static BytesReference parseSourceBytes(XContentParser parser) throws IOException {
try (XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent())) {
// the original document gets slightly modified: whitespaces or
// pretty printing are not preserved,
// it all depends on the current builder settings
builder.copyCurrentStructure(parser);
return BytesReference.bytes(builder);
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
private static BytesReference parseSourceBytes(XContentParser parser) throws IOException {
try (XContentBuilder builder = XContentBuilder.builder(parser.contentType().xContent())) {
// the original document gets slightly modified: whitespaces or
// pretty printing are not preserved,
// it all depends on the current builder settings
builder.copyCurrentStructure(parser);
return BytesReference.bytes(builder);
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
private static Script extractConditional(Map<String, Object> config) throws IOException {
Object scriptSource = config.remove("if");
if (scriptSource != null) {
try (XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent)
.map(normalizeScript(scriptSource));
InputStream stream = BytesReference.bytes(builder).streamInput();
XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE, stream)) {
return Script.parse(parser);
}
}
return null;
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
private static String arrayToParsableString(String[] array) {
try {
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
builder.startArray();
for (String element : array) {
builder.value(element);
}
builder.endArray();
return builder.string();
} catch (IOException ex) {
throw new ElasticsearchException(ex);
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
private static String arrayToParsableString(List<String> array) {
try {
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
builder.startArray();
for (String element : array) {
builder.value(element);
}
builder.endArray();
return Strings.toString(builder);
} catch (IOException ex) {
throw new ElasticsearchException(ex);
}
}
内容来源于网络,如有侵权,请联系作者删除!