本文整理了Java中org.elasticsearch.common.xcontent.XContentBuilder.string()
方法的一些代码示例,展示了XContentBuilder.string()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XContentBuilder.string()
方法的具体详情如下:
包路径:org.elasticsearch.common.xcontent.XContentBuilder
类名称:XContentBuilder
方法名:string
[英]Returns a string representation of the builder (only applicable for text based xcontent).
[中]返回生成器的字符串表示形式(仅适用于基于文本的xcontent)。
代码示例来源:origin: thinkaurelius/titan
private static String convertToJsType(Object value) throws PermanentBackendException {
try {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
builder.field("value", convertToEsType(value));
String s = builder.string();
int prefixLength = "{\"value\":".length();
int suffixLength = "}".length();
String result = s.substring(prefixLength, s.length() - suffixLength);
result = result.replace("$", "\\$");
return result;
} catch (IOException e) {
throw new PermanentBackendException("Could not write json");
}
}
代码示例来源:origin: brianfrankcooper/YCSB
private Response search(final String table, final XContentBuilder builder) throws IOException {
refreshIfNeeded();
final Map<String, String> params = emptyMap();
final StringEntity entity = new StringEntity(builder.string());
final Header header = new BasicHeader("content-type", ContentType.APPLICATION_JSON.toString());
return restClient.performRequest("GET", "/" + indexKey + "/" + table + "/_search", params, entity, header);
}
代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb
private XContentBuilder getGridFSMapping() throws IOException {
XContentBuilder mapping = jsonBuilder()
.startObject()
.startObject(definition.getTypeName())
.startObject("properties")
.startObject("content").field("type", "attachment").endObject()
.startObject("filename").field("type", "string").endObject()
.startObject("contentType").field("type", "string").endObject()
.startObject("md5").field("type", "string").endObject()
.startObject("length").field("type", "long").endObject()
.startObject("chunkSize").field("type", "long").endObject()
.endObject()
.endObject()
.endObject();
logger.info("GridFS Mapping: {}", mapping.string());
return mapping;
}
代码示例来源:origin: brianfrankcooper/YCSB
builder.endObject();
final Map<String, String> params = emptyMap();
final StringEntity entity = new StringEntity(builder.string());
final Response createResponse = performRequest(restClient, "PUT", "/" + indexKey, params, entity);
final int statusCode = createResponse.getStatusLine().getStatusCode();
代码示例来源:origin: prestodb/presto
@Override
public void addResults(QueryStatusInfo statusInfo, QueryData data)
{
if (types.get() == null && statusInfo.getColumns() != null) {
types.set(getTypes(statusInfo.getColumns()));
}
if (data.getData() == null) {
return;
}
checkState(types.get() != null, "Type information is missing");
List<Column> columns = statusInfo.getColumns();
for (List<Object> fields : data.getData()) {
try {
XContentBuilder dataBuilder = jsonBuilder().startObject();
for (int i = 0; i < fields.size(); i++) {
Type type = types.get().get(i);
Object value = convertValue(fields.get(i), type);
dataBuilder.field(columns.get(i).getName(), value);
}
dataBuilder.endObject();
client.prepareIndex(tableName, "doc")
.setSource(dataBuilder.string(), JSON)
.get();
}
catch (IOException e) {
throw new UncheckedIOException("Error loading data into Elasticsearch index: " + tableName, e);
}
}
}
代码示例来源:origin: komoot/photon
@Override
public void add(PhotonDoc doc) {
try {
writer.println("{\"index\": {}}");
writer.println(Utils.convert(doc, this.languages).string());
} catch (IOException e) {
log.error("error writing json file", e);
}
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
public static String toXContent(MetaData metaData, ToXContent.Params params) throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.startObject();
toXContent(metaData, builder, params);
builder.endObject();
return builder.string();
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
/**
* The mapping source definition.
*/
public PutMappingRequest source(XContentBuilder mappingBuilder) {
try {
return source(mappingBuilder.string(), mappingBuilder.contentType());
} catch (IOException e) {
throw new IllegalArgumentException("Failed to build json for mapping request", e);
}
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
@Override
public String toString() {
try {
return toXContent(JsonXContent.contentBuilder(), ToXContent.EMPTY_PARAMS).string();
} catch (IOException e) {
return super.toString();
}
}
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
@Override
public String toString() {
try {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
toXContent(builder, EMPTY_PARAMS);
builder.endObject();
return builder.string();
} catch (IOException e) {
return "{ \"error\" : \"" + e.getMessage() + "\"}";
}
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
@Override
public synchronized String toString() {
try {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
toXContent(builder, EMPTY_PARAMS);
builder.endObject();
return builder.string();
} catch (IOException e) {
return "{ \"error\" : \"" + e.getMessage() + "\"}";
}
}
代码示例来源:origin: com.strapdata.elasticsearch.test/framework
public void testEmptyName() throws IOException {
// after version 5
for (String type : TYPES) {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("").field("type", type).endObject().endObject()
.endObject().endObject().string();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> parser.parse("type", new CompressedXContent(mapping))
);
assertThat(e.getMessage(), containsString("name cannot be empty string"));
}
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
public Builder filter(XContentBuilder filterBuilder) {
try {
return filter(filterBuilder.string());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
}
}
代码示例来源:origin: com.strapdata.elasticsearch.test/framework
/**
* Prints the segments info for the given indices as debug logging.
*/
public void logSegmentsState(String... indices) throws Exception {
IndicesSegmentResponse segsRsp = client().admin().indices().prepareSegments(indices).get();
logger.debug("segments {} state: \n{}", indices.length == 0 ? "[_all]" : indices,
segsRsp.toXContent(JsonXContent.contentBuilder().prettyPrint(), ToXContent.EMPTY_PARAMS).string());
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
/**
* Allows to set the settings using a json builder.
*/
public CreateIndexRequest settings(XContentBuilder builder) {
try {
settings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate json settings from builder", e);
}
return this;
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
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(builder.string(), builder.contentType()).build();
} catch (IOException e) {
throw new IllegalArgumentException("Failed to parse [" + definition + "]", e);
}
}
代码示例来源:origin: dremio/dremio-oss
public static String queryAsJson(QueryBuilder query) throws IOException {
XContentBuilder x = XContentFactory.jsonBuilder();
x.prettyPrint().lfAtEnd();
query.toXContent(x, ToXContent.EMPTY_PARAMS);
return x.string();
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
@Override
public String toString() {
try {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.prettyPrint();
toXContent(builder, EMPTY_PARAMS);
return builder.string();
} catch (Exception e) {
return "{ \"error\" : \"" + ExceptionsHelper.detailedMessage(e) + "\"}";
}
}
代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch
@Override
public String toString() {
try {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.prettyPrint();
toXContent(builder, EMPTY_PARAMS);
return builder.string();
} catch (Exception e) {
return "{ \"error\" : \"" + ExceptionsHelper.detailedMessage(e) + "\"}";
}
}
代码示例来源:origin: com.scireum/sirius-search
@Override
public Object eval(LocalRenderContext ctx, Expression[] args) {
try (XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint()) {
return ((ToXContent) args[0].eval(ctx)).toXContent(builder, ToXContent.EMPTY_PARAMS).string();
} catch (IOException e) {
Exceptions.handle(e);
}
return "";
}
内容来源于网络,如有侵权,请联系作者删除!