本文整理了Java中org.elasticsearch.common.xcontent.XContentBuilder.copyCurrentStructure()
方法的一些代码示例,展示了XContentBuilder.copyCurrentStructure()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XContentBuilder.copyCurrentStructure()
方法的具体详情如下:
包路径:org.elasticsearch.common.xcontent.XContentBuilder
类名称:XContentBuilder
方法名:copyCurrentStructure
暂无
代码示例来源:origin: floragunncom/search-guard
private static BytesReference readXContent(final Reader reader, final XContentType xContentType) throws IOException {
BytesReference retVal;
XContentParser parser = null;
try {
parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, reader);
parser.nextToken();
final XContentBuilder builder = XContentFactory.jsonBuilder();
builder.copyCurrentStructure(parser);
retVal = BytesReference.bytes(builder);
} finally {
if (parser != null) {
parser.close();
}
}
//validate
Settings.builder().loadFromStream("dummy.json", new ByteArrayInputStream(BytesReference.toBytes(retVal)), true).build();
return retVal;
}
代码示例来源:origin: floragunncom/search-guard
public static BytesReference readXContent(final Reader reader, final XContentType xContentType) throws IOException {
BytesReference retVal;
XContentParser parser = null;
try {
parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, reader);
parser.nextToken();
final XContentBuilder builder = XContentFactory.jsonBuilder();
builder.copyCurrentStructure(parser);
retVal = BytesReference.bytes(builder);
} finally {
if (parser != null) {
parser.close();
}
}
//validate
Settings.builder().loadFromStream("dummy.json", new ByteArrayInputStream(BytesReference.toBytes(retVal)), true).build();
return retVal;
}
代码示例来源:origin: floragunncom/search-guard
public static BytesReference readYamlContentFromString(final String yaml) {
XContentParser parser = null;
try {
parser = XContentFactory.xContent(XContentType.YAML).createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, new StringReader(yaml));
parser.nextToken();
final XContentBuilder builder = XContentFactory.jsonBuilder();
builder.copyCurrentStructure(parser);
return BytesReference.bytes(builder);
} catch (Exception e) {
throw new RuntimeException(e);
}
finally {
if (parser != null) {
try {
parser.close();
} catch (IOException e) {
//ignore
}
}
}
}
}
代码示例来源:origin: floragunncom/search-guard
public static BytesReference readYamlContent(final String file) {
XContentParser parser = null;
try {
parser = XContentFactory.xContent(XContentType.YAML).createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, new StringReader(loadFile(file)));
parser.nextToken();
final XContentBuilder builder = XContentFactory.jsonBuilder();
builder.copyCurrentStructure(parser);
return BytesReference.bytes(builder);
} catch (Exception e) {
throw new RuntimeException(e);
}
finally {
if (parser != null) {
try {
parser.close();
} catch (IOException e) {
//ignore
}
}
}
}
代码示例来源:origin: apache/flume
builder.copyCurrentStructure(parser);
} catch (JsonParseException ex) {
代码示例来源:origin: spring-projects/spring-data-elasticsearch
indexXContentType)) {
try (XContentBuilder builder = XContentBuilder.builder(bulkContentType.xContent())) {
builder.copyCurrentStructure(parser);
source = BytesReference.bytes(builder).toBytesRef();
代码示例来源:origin: org.elasticsearch/elasticsearch
private static StoredScriptSource parseRemaining(Token token, XContentParser parser) throws IOException {
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
if (token != Token.START_OBJECT) {
builder.startObject();
builder.copyCurrentStructure(parser);
builder.endObject();
} else {
builder.copyCurrentStructure(parser);
}
String source = Strings.toString(builder);
if (source == null || source.isEmpty()) {
DEPRECATION_LOGGER.deprecated("empty templates should no longer be used");
}
return new StoredScriptSource(Script.DEFAULT_TEMPLATE_LANG, source, Collections.emptyMap());
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("index_patterns", indexPatterns);
builder.field("order", order);
if (version != null) {
builder.field("version", version);
}
builder.startObject("settings");
settings.toXContent(builder, params);
builder.endObject();
builder.startObject("mappings");
for (Map.Entry<String, String> entry : mappings.entrySet()) {
builder.field(entry.getKey());
XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, entry.getValue());
builder.copyCurrentStructure(parser);
}
builder.endObject();
builder.startObject("aliases");
for (Alias alias : aliases) {
alias.toXContent(builder, params);
}
builder.endObject();
return builder;
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Helper to declare an object that will be parsed into a {@link BytesReference}
*/
public void declareRawObject(final AbstractObjectParser<Value, Context> parser,
final BiConsumer<Value, BytesReference> consumer,
final ParseField field) {
final CheckedFunction<XContentParser, BytesReference, IOException> bytesParser = p -> {
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
builder.copyCurrentStructure(p);
return BytesReference.bytes(builder);
}
};
parser.declareField(consumer, bytesParser, field, ValueType.OBJECT);
}
代码示例来源: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
/**
* Since stored scripts can accept templates rather than just scripts, they must also be able
* to handle template parsing, hence the need for custom parsing source. Templates can
* consist of either an {@link String} or a JSON object. If a JSON object is discovered
* then the content type option must also be saved as a compiler option.
*/
private void setSource(XContentParser parser) {
try {
if (parser.currentToken() == Token.START_OBJECT) {
// this is really for search templates, that need to be converted to json format
XContentBuilder builder = XContentFactory.jsonBuilder();
source = Strings.toString(builder.copyCurrentStructure(parser));
options.put(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType());
} else {
source = parser.text();
}
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* Since inline scripts can accept code rather than just an id, they must also be able
* to handle template parsing, hence the need for custom parsing code. Templates can
* consist of either an {@link String} or a JSON object. If a JSON object is discovered
* then the content type option must also be saved as a compiler option.
*/
private void setInline(XContentParser parser) {
try {
if (type != null) {
throwOnlyOneOfType();
}
type = ScriptType.INLINE;
if (parser.currentToken() == Token.START_OBJECT) {
//this is really for search templates, that need to be converted to json format
XContentBuilder builder = XContentFactory.jsonBuilder();
idOrCode = Strings.toString(builder.copyCurrentStructure(parser));
options.put(CONTENT_TYPE_OPTION, XContentType.JSON.mediaType());
} else {
idOrCode = parser.text();
}
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static String convertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint, XContentType xContentType)
throws IOException {
Objects.requireNonNull(xContentType);
if (xContentType == XContentType.JSON && !reformatJson) {
return bytes.utf8ToString();
}
// It is safe to use EMPTY here because this never uses namedObject
try (InputStream stream = bytes.streamInput();
XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, stream)) {
parser.nextToken();
XContentBuilder builder = XContentFactory.jsonBuilder();
if (prettyPrint) {
builder.prettyPrint();
}
builder.copyCurrentStructure(parser);
return Strings.toString(builder);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
} else if ("upsert".equals(currentFieldName)) {
XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType());
builder.copyCurrentStructure(parser);
safeUpsertRequest().source(builder);
} else if ("doc".equals(currentFieldName)) {
XContentBuilder docBuilder = XContentFactory.contentBuilder(parser.contentType());
docBuilder.copyCurrentStructure(parser);
safeDoc().source(docBuilder);
} else if ("doc_as_upsert".equals(currentFieldName)) {
代码示例来源:origin: org.elasticsearch/elasticsearch
builder.copyCurrentStructure(parser);
source = BytesReference.bytes(builder);
代码示例来源:origin: org.elasticsearch/elasticsearch
LoggingDeprecationHandler.INSTANCE, doc.source(), xContentType)) {
builder.field("doc");
builder.copyCurrentStructure(parser);
LoggingDeprecationHandler.INSTANCE, upsertRequest.source(), xContentType)) {
builder.field("upsert");
builder.copyCurrentStructure(parser);
代码示例来源:origin: org.elasticsearch/elasticsearch
fieldName = currentFieldName;
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.copyCurrentStructure(parser);
functionBytes = BytesReference.bytes(builder);
} else if (MULTI_VALUE_MODE.match(currentFieldName, parser.getDeprecationHandler())) {
代码示例来源:origin: org.elasticsearch/elasticsearch
"either [id] or [doc] can be specified, but not both!");
termVectorsRequest.doc(jsonBuilder().copyCurrentStructure(parser));
} else if (ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
termVectorsRequest.routing = parser.text();
代码示例来源:origin: org.elasticsearch/elasticsearch
item.id = parser.text();
} else if (DOC.match(currentFieldName, parser.getDeprecationHandler())) {
item.doc = BytesReference.bytes(jsonBuilder().copyCurrentStructure(parser));
item.xContentType = XContentType.JSON;
} else if (FIELDS.match(currentFieldName, parser.getDeprecationHandler())) {
代码示例来源:origin: org.elasticsearch.client/elasticsearch-rest-high-level-client
private static BytesReference readBytesReference(XContentParser parser) throws IOException {
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
builder.copyCurrentStructure(parser);
return BytesReference.bytes(builder);
}
}
内容来源于网络,如有侵权,请联系作者删除!