本文整理汇总了Java中org.elasticsearch.common.xcontent.ToXContent类的典型用法代码示例。如果您正苦于以下问题:Java ToXContent类的具体用法?Java ToXContent怎么用?Java ToXContent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ToXContent类属于org.elasticsearch.common.xcontent包,在下文中一共展示了ToXContent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filter
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
/**
* Associates a filter to the alias
*/
public Alias filter(QueryBuilder filterBuilder) {
if (filterBuilder == null) {
this.filter = null;
return this;
}
try {
XContentBuilder builder = XContentFactory.jsonBuilder();
filterBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.close();
this.filter = builder.string();
return this;
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
}
}
示例2: toXContent
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject();
builder.startArray(Fields.RESPONSES);
for (Item item : items) {
if (item.isFailure()) {
builder.startObject();
ElasticsearchException.generateFailureXContent(builder, params, item.getFailure(), true);
builder.endObject();
} else {
item.getResponse().toXContent(builder, params);
}
}
builder.endArray();
builder.endObject();
return builder;
}
示例3: toXContent
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
/**
* Renders the provided instance in XContent
*
* @param instance
* the instance to render
* @param contentType
* the content type to render to
*/
protected XContentBuilder toXContent(T instance, XContentType contentType)
throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(contentType);
if (randomBoolean()) {
builder.prettyPrint();
}
if (instance.isFragment()) {
builder.startObject();
}
instance.toXContent(builder, ToXContent.EMPTY_PARAMS);
if (instance.isFragment()) {
builder.endObject();
}
return builder;
}
示例4: testCheckpointsAdvance
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
public void testCheckpointsAdvance() throws Exception {
try (ReplicationGroup shards = createGroup(randomInt(3))) {
shards.startPrimary();
int numDocs = 0;
int startedShards;
do {
numDocs += shards.indexDocs(randomInt(20));
startedShards = shards.startReplicas(randomIntBetween(1, 2));
} while (startedShards > 0);
if (numDocs == 0 || randomBoolean()) {
// in the case we have no indexing, we simulate the background global checkpoint sync
shards.getPrimary().updateGlobalCheckpointOnPrimary();
}
for (IndexShard shard : shards) {
final SeqNoStats shardStats = shard.seqNoStats();
final ShardRouting shardRouting = shard.routingEntry();
logger.debug("seq_no stats for {}: {}", shardRouting, XContentHelper.toString(shardStats,
new ToXContent.MapParams(Collections.singletonMap("pretty", "false"))));
assertThat(shardRouting + " local checkpoint mismatch", shardStats.getLocalCheckpoint(), equalTo(numDocs - 1L));
assertThat(shardRouting + " global checkpoint mismatch", shardStats.getGlobalCheckpoint(), equalTo(numDocs - 1L));
assertThat(shardRouting + " max seq no mismatch", shardStats.getMaxSeqNo(), equalTo(numDocs - 1L));
}
}
}
示例5: toXContent
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder = builder.startObject()
.field(NAME.getPreferredName(), getName())
.field(REASON.getPreferredName(), getReason())
.timeValueField(TIME_NANOS.getPreferredName(), TIME.getPreferredName(), getTime(), TimeUnit.NANOSECONDS);
if (!children.isEmpty()) {
builder = builder.startArray(CHILDREN.getPreferredName());
for (CollectorResult child : children) {
builder = child.toXContent(builder, params);
}
builder = builder.endArray();
}
builder = builder.endObject();
return builder;
}
示例6: contexts
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
/**
* Sets query contexts for completion
* @param queryContexts named query contexts
* see {@link org.elasticsearch.search.suggest.completion.context.CategoryQueryContext}
* and {@link org.elasticsearch.search.suggest.completion.context.GeoQueryContext}
*/
public CompletionSuggestionBuilder contexts(Map<String, List<? extends ToXContent>> queryContexts) {
Objects.requireNonNull(queryContexts, "contexts must not be null");
try {
XContentBuilder contentBuilder = XContentFactory.jsonBuilder();
contentBuilder.startObject();
for (Map.Entry<String, List<? extends ToXContent>> contextEntry : queryContexts.entrySet()) {
contentBuilder.startArray(contextEntry.getKey());
for (ToXContent queryContext : contextEntry.getValue()) {
queryContext.toXContent(contentBuilder, EMPTY_PARAMS);
}
contentBuilder.endArray();
}
contentBuilder.endObject();
return contexts(contentBuilder);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
示例7: testFromXContent
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
/**
* Test that creates new shape from a random test shape and checks both for equality
*/
public void testFromXContent() throws IOException {
for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {
SB testShape = createTestShapeBuilder();
XContentBuilder contentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
if (randomBoolean()) {
contentBuilder.prettyPrint();
}
XContentBuilder builder = testShape.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
XContentBuilder shuffled = shuffleXContent(builder);
XContentParser shapeParser = createParser(shuffled);
shapeParser.nextToken();
ShapeBuilder parsedShape = ShapeBuilder.parse(shapeParser);
assertNotSame(testShape, parsedShape);
assertEquals(testShape, parsedShape);
assertEquals(testShape.hashCode(), parsedShape.hashCode());
}
}
示例8: build
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
private static XContentBuilder build(RestChannel channel, RestStatus status, Exception e) throws IOException {
ToXContent.Params params = channel.request();
if (params.paramAsBoolean("error_trace", !REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT)) {
params = new ToXContent.DelegatingMapParams(singletonMap(REST_EXCEPTION_SKIP_STACK_TRACE, "false"), params);
} else if (e != null) {
Supplier<?> messageSupplier = () -> new ParameterizedMessage("path: {}, params: {}",
channel.request().rawPath(), channel.request().params());
if (status.getStatus() < 500) {
SUPPRESSED_ERROR_LOGGER.debug(messageSupplier, e);
} else {
SUPPRESSED_ERROR_LOGGER.warn(messageSupplier, e);
}
}
XContentBuilder builder = channel.newErrorBuilder().startObject();
ElasticsearchException.generateFailureXContent(builder, params, e, channel.detailedErrorsEnabled());
builder.field(STATUS, status.getStatus());
builder.endObject();
return builder;
}
示例9: renderResponse
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
private XContentBuilder renderResponse(ClusterState state, boolean renderDefaults, XContentBuilder builder, ToXContent.Params params)
throws IOException {
builder.startObject();
builder.startObject("persistent");
state.metaData().persistentSettings().toXContent(builder, params);
builder.endObject();
builder.startObject("transient");
state.metaData().transientSettings().toXContent(builder, params);
builder.endObject();
if (renderDefaults) {
builder.startObject("defaults");
settingsFilter.filter(clusterSettings.diff(state.metaData().settings(), this.settings)).toXContent(builder, params);
builder.endObject();
}
builder.endObject();
return builder;
}
示例10: toXContent
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
public static void toXContent(AliasMetaData aliasMetaData, XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject(aliasMetaData.alias());
boolean binary = params.paramAsBoolean("binary", false);
if (aliasMetaData.filter() != null) {
if (binary) {
builder.field("filter", aliasMetaData.filter.compressed());
} else {
builder.field("filter", XContentHelper.convertToMap(new BytesArray(aliasMetaData.filter().uncompressed()), true).v2());
}
}
if (aliasMetaData.indexRouting() != null) {
builder.field("index_routing", aliasMetaData.indexRouting());
}
if (aliasMetaData.searchRouting() != null) {
builder.field("search_routing", aliasMetaData.searchRouting());
}
builder.endObject();
}
示例11: toXContent
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder = builder.startObject()
.field(NAME.getPreferredName(), getName())
.field(REASON.getPreferredName(), getReason())
.field(TIME.getPreferredName(), String.format(Locale.US, "%.10gms", (double) (getTime() / 1000000.0)));
if (!children.isEmpty()) {
builder = builder.startArray(CHILDREN.getPreferredName());
for (CollectorResult child : children) {
builder = child.toXContent(builder, params);
}
builder = builder.endArray();
}
builder = builder.endObject();
return builder;
}
示例12: toXContent
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
/**
* Serializes file info into JSON
*
* @param file file info
* @param builder XContent builder
* @param params parameters
*/
public static void toXContent(FileInfo file, XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject();
builder.field(Fields.NAME, file.name);
builder.field(Fields.PHYSICAL_NAME, file.metadata.name());
builder.field(Fields.LENGTH, file.metadata.length());
if (file.metadata.checksum() != null) {
builder.field(Fields.CHECKSUM, file.metadata.checksum());
}
if (file.partSize != null) {
builder.field(Fields.PART_SIZE, file.partSize.bytes());
}
if (file.metadata.writtenBy() != null) {
builder.field(Fields.WRITTEN_BY, file.metadata.writtenBy());
}
if (file.metadata.hash() != null && file.metadata().hash().length > 0) {
builder.field(Fields.META_HASH, file.metadata.hash());
}
builder.endObject();
}
示例13: explain
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
@Override
public String explain() {
try {
XContentBuilder firstBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
this.firstSearchRequest.request().source().toXContent(firstBuilder, ToXContent.EMPTY_PARAMS);
XContentBuilder secondBuilder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
this.secondSearchRequest.request().source().toXContent(secondBuilder, ToXContent.EMPTY_PARAMS);
String explained = String.format("performing %s on :\n left query:\n%s\n right query:\n%s", this.relation.name,firstBuilder.string(), secondBuilder.string());
return explained;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例14: compareJsonOutput
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
private void compareJsonOutput(ToXContent param1, ToXContent param2) throws IOException {
if (param1 == null) {
assertNull(param2);
return;
}
ToXContent.Params params = ToXContent.EMPTY_PARAMS;
XContentBuilder param1Builder = jsonBuilder();
param1Builder.startObject();
param1.toXContent(param1Builder, params);
param1Builder.endObject();
XContentBuilder param2Builder = jsonBuilder();
param2Builder.startObject();
param2.toXContent(param2Builder, params);
param2Builder.endObject();
assertThat(param1Builder.string(), equalTo(param2Builder.string()));
}
示例15: testXContentRoundTrip
import org.elasticsearch.common.xcontent.ToXContent; //导入依赖的package包/类
public void testXContentRoundTrip() throws IOException {
/*
* Note that this round trip isn't 100% perfect - status will always be read as RawTaskStatus. Since this test uses RawTaskStatus
* as the status we randomly generate then we can assert the round trip with .equals.
*/
TaskResult result = randomTaskResult();
TaskResult read;
try (XContentBuilder builder = XContentBuilder.builder(randomFrom(XContentType.values()).xContent())) {
result.toXContent(builder, ToXContent.EMPTY_PARAMS);
try (XContentBuilder shuffled = shuffleXContent(builder);
XContentParser parser = createParser(shuffled)) {
read = TaskResult.PARSER.apply(parser, null);
}
} catch (IOException e) {
throw new IOException("Error processing [" + result + "]", e);
}
assertEquals(result, read);
}