Java Code Examples for org.elasticsearch.common.xcontent.ToXContent#Params

The following examples show how to use org.elasticsearch.common.xcontent.ToXContent#Params . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractXContentTestCase.java    From crate with Apache License 2.0 6 votes vote down vote up
public static <T extends ToXContent> void testFromXContent(
        int numberOfTestRuns,
        Supplier<T> instanceSupplier,
        boolean supportsUnknownFields,
        String[] shuffleFieldsExceptions,
        Predicate<String> randomFieldsExcludeFilter,
        CheckedBiFunction<XContent, BytesReference, XContentParser, IOException> createParserFunction,
        CheckedFunction<XContentParser, T, IOException> fromXContent,
        BiConsumer<T, T> assertEqualsConsumer,
        boolean assertToXContentEquivalence,
        ToXContent.Params toXContentParams) throws IOException {
    xContentTester(createParserFunction, instanceSupplier, toXContentParams, fromXContent)
            .numberOfTestRuns(numberOfTestRuns)
            .supportsUnknownFields(supportsUnknownFields)
            .shuffleFieldsExceptions(shuffleFieldsExceptions)
            .randomFieldsExcludeFilter(randomFieldsExcludeFilter)
            .assertEqualsConsumer(assertEqualsConsumer)
            .assertToXContentEquivalence(assertToXContentEquivalence)
            .test();
}
 
Example 2
Source File: ShardExportResponse.java    From elasticsearch-inout-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startObject();
    builder.field("index", getIndex());
    builder.field("shard", getShardId());
    if (node != null) {
        builder.field("node_id", node);
    }
    builder.field("numExported", getNumExported());
    if (getFile() != null) {
        builder.field("output_file", getFile());
    } else {
        builder.field("output_cmd", getCmd() != null ? getCmd() : getCmdArray());
        if (!dryRun()) {
            builder.field("stderr", getStderr());
            builder.field("stdout", getStdout());
            builder.field("exitcode", getExitCode());
        }
    }
    builder.endObject();
    return builder;
}
 
Example 3
Source File: LangdetectResponse.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    if (!Strings.isNullOrEmpty(profile)) {
        builder.field("profile", profile);
    }
    builder.startArray("languages");
    for (Language lang : languages) {
        builder.startObject().field("language", lang.getLanguage())
                .field("probability", lang.getProbability()).endObject();
    }
    builder.endArray();
    return builder;
}
 
Example 4
Source File: CancelAllocationCommand.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void toXContent(CancelAllocationCommand command, XContentBuilder builder, ToXContent.Params params, String objectName) throws IOException {
    if (objectName == null) {
        builder.startObject();
    } else {
        builder.startObject(objectName);
    }
    builder.field("index", command.shardId().index().name());
    builder.field("shard", command.shardId().id());
    builder.field("node", command.node());
    builder.field("allow_primary", command.allowPrimary());
    builder.endObject();
}
 
Example 5
Source File: AllocationCommands.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Writes {@link AllocationCommands} to a {@link XContentBuilder}
 * 
 * @param commands {@link AllocationCommands} to write
 * @param builder {@link XContentBuilder} to use
 * @param params Parameters to use for building
 * @throws IOException if something bad happens while building the content
 */
public static void toXContent(AllocationCommands commands, XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startArray("commands");
    for (AllocationCommand command : commands.commands) {
        builder.startObject();
        builder.field(command.name());
        AllocationCommands.lookupFactorySafe(command.name()).toXContent(command, builder, params, null);
        builder.endObject();
    }
    builder.endArray();
}
 
Example 6
Source File: GetIndexRequestRestListener.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
private void writeAliases(List<AliasMetadata> aliases, XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startObject(Fields.ALIASES);
    if (aliases != null) {
        for (AliasMetadata alias : aliases) {
            AliasMetadata.Builder.toXContent(alias, builder, params);
        }
    }
    builder.endObject();
}
 
Example 7
Source File: MetaStateService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a StateFormat that can read and write {@link IndexMetaData}
 */
static MetaDataStateFormat<IndexMetaData> indexStateFormat(XContentType format, final ToXContent.Params formatParams) {
    return new MetaDataStateFormat<IndexMetaData>(format, INDEX_STATE_FILE_PREFIX) {

        @Override
        public void toXContent(XContentBuilder builder, IndexMetaData state) throws IOException {
            IndexMetaData.Builder.toXContent(state, builder, formatParams);            }

        @Override
        public IndexMetaData fromXContent(XContentParser parser) throws IOException {
            return IndexMetaData.Builder.fromXContent(parser);
        }
    };
}
 
Example 8
Source File: FieldDataTermsQueryBuilder.java    From siren-join with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void doXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
  builder.startObject(FieldDataTermsQueryParser.NAME);
    builder.startObject(name);
      builder.field("value", value);
      builder.field("_cache_key", cacheKey);
    builder.endObject();
  builder.endObject();
}
 
Example 9
Source File: ThreadPoolStats.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startObject(Fields.THREAD_POOL);
    for (Stats stat : stats) {
        stat.toXContent(builder, params);
    }
    builder.endObject();
    return builder;
}
 
Example 10
Source File: SnapshotsInProgress.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void toXContent(Entry entry, XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startObject();
    builder.field(Fields.REPOSITORY, entry.snapshotId().getRepository());
    builder.field(Fields.SNAPSHOT, entry.snapshotId().getSnapshot());
    builder.field(Fields.INCLUDE_GLOBAL_STATE, entry.includeGlobalState());
    builder.field(Fields.STATE, entry.state());
    builder.startArray(Fields.INDICES);
    {
        for (String index : entry.indices()) {
            builder.value(index);
        }
    }
    builder.endArray();
    builder.timeValueField(Fields.START_TIME_MILLIS, Fields.START_TIME, entry.startTime());
    builder.startArray(Fields.SHARDS);
    {
        for (Map.Entry<ShardId, ShardSnapshotStatus> shardEntry : entry.shards.entrySet()) {
            ShardId shardId = shardEntry.getKey();
            ShardSnapshotStatus status = shardEntry.getValue();
            builder.startObject();
            {
                builder.field(Fields.INDEX, shardId.getIndex());
                builder.field(Fields.SHARD, shardId.getId());
                builder.field(Fields.STATE, status.state());
                builder.field(Fields.NODE, status.nodeId());
            }
            builder.endObject();
        }
    }
    builder.endArray();
    builder.endObject();
}
 
Example 11
Source File: IndicesOptions.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startArray("expand_wildcards");
    for (WildcardStates expandWildcard : expandWildcards) {
        builder.value(expandWildcard.toString().toLowerCase(Locale.ROOT));
    }
    builder.endArray();
    builder.field("ignore_unavailable", ignoreUnavailable());
    builder.field("allow_no_indices", allowNoIndices());
    return builder;
}
 
Example 12
Source File: CompressedXContent.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@link CompressedXContent} out of a {@link ToXContent} instance.
 */
public CompressedXContent(ToXContent xcontent, XContentType type, ToXContent.Params params) throws IOException {
    BytesStreamOutput bStream = new BytesStreamOutput();
    OutputStream compressedStream = CompressorFactory.defaultCompressor().streamOutput(bStream);
    CRC32 crc32 = new CRC32();
    OutputStream checkedStream = new CheckedOutputStream(compressedStream, crc32);
    try (XContentBuilder builder = XContentFactory.contentBuilder(type, checkedStream)) {
        builder.startObject();
        xcontent.toXContent(builder, params);
        builder.endObject();
    }
    this.bytes = bStream.bytes().toBytes();
    this.crc32 = (int) crc32.getValue();
    assertConsistent();
}
 
Example 13
Source File: SnapshotsInProgress.java    From crate with Apache License 2.0 5 votes vote down vote up
public void toXContent(Entry entry, XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startObject();
    builder.field(REPOSITORY, entry.snapshot().getRepository());
    builder.field(SNAPSHOT, entry.snapshot().getSnapshotId().getName());
    builder.field(UUID, entry.snapshot().getSnapshotId().getUUID());
    builder.field(INCLUDE_GLOBAL_STATE, entry.includeGlobalState());
    builder.field(PARTIAL, entry.partial());
    builder.field(STATE, entry.state());
    builder.startArray(INDICES);
    {
        for (IndexId index : entry.indices()) {
            index.toXContent(builder, params);
        }
    }
    builder.endArray();
    builder.humanReadableField(START_TIME_MILLIS, START_TIME, new TimeValue(entry.startTime()));
    builder.field(REPOSITORY_STATE_ID, entry.getRepositoryStateId());
    builder.startArray(SHARDS);
    {
        for (ObjectObjectCursor<ShardId, ShardSnapshotStatus> shardEntry : entry.shards) {
            ShardId shardId = shardEntry.key;
            ShardSnapshotStatus status = shardEntry.value;
            builder.startObject();
            {
                builder.field(INDEX, shardId.getIndex());
                builder.field(SHARD, shardId.getId());
                builder.field(STATE, status.state());
                builder.field(NODE, status.nodeId());
            }
            builder.endObject();
        }
    }
    builder.endArray();
    builder.endObject();
}
 
Example 14
Source File: RootObjectMapper.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    final boolean includeDefaults = params.paramAsBoolean("include_defaults", false);

    if (dynamicDateTimeFormatters.explicit() || includeDefaults) {
        builder.startArray("dynamic_date_formats");
        for (FormatDateTimeFormatter dateTimeFormatter : dynamicDateTimeFormatters.value()) {
            builder.value(dateTimeFormatter.format());
        }
        builder.endArray();
    }

    if (dynamicTemplates.explicit() || includeDefaults) {
        builder.startArray("dynamic_templates");
        for (DynamicTemplate dynamicTemplate : dynamicTemplates.value()) {
            builder.startObject();
            builder.field(dynamicTemplate.name(), dynamicTemplate);
            builder.endObject();
        }
        builder.endArray();
    }

    if (dateDetection.explicit() || includeDefaults) {
        builder.field("date_detection", dateDetection.value());
    }
    if (numericDetection.explicit() || includeDefaults) {
        builder.field("numeric_detection", numericDetection.value());
    }
}
 
Example 15
Source File: IndexWarmersMetaData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    //No need, IndexMetaData already writes it
    //builder.startObject(TYPE, XContentBuilder.FieldCaseConversion.NONE);
    for (Entry entry : entries()) {
        toXContent(entry, builder, params);
    }
    //No need, IndexMetaData already writes it
    //builder.endObject();
    return builder;
}
 
Example 16
Source File: SnapshotInfo.java    From crate with Apache License 2.0 5 votes vote down vote up
private XContentBuilder toXContentInternal(final XContentBuilder builder, final ToXContent.Params params) throws IOException {
    builder.startObject(SNAPSHOT);
    builder.field(NAME, snapshotId.getName());
    builder.field(UUID, snapshotId.getUUID());
    assert version != null : "version must always be known when writing a snapshot metadata blob";
    builder.field(VERSION_ID, version.internalId);
    builder.startArray(INDICES);
    for (String index : indices) {
        builder.value(index);
    }
    builder.endArray();
    builder.field(STATE, state);
    if (reason != null) {
        builder.field(REASON, reason);
    }
    if (includeGlobalState != null) {
        builder.field(INCLUDE_GLOBAL_STATE, includeGlobalState);
    }
    builder.field(START_TIME, startTime);
    builder.field(END_TIME, endTime);
    builder.field(TOTAL_SHARDS, totalShards);
    builder.field(SUCCESSFUL_SHARDS, successfulShards);
    builder.startArray(FAILURES);
    for (SnapshotShardFailure shardFailure : shardFailures) {
        builder.startObject();
        shardFailure.toXContent(builder, params);
        builder.endObject();
    }
    builder.endArray();
    builder.endObject();
    return builder;
}
 
Example 17
Source File: GetIndexRequestRestListener.java    From elasticsearch-sql with Apache License 2.0 4 votes vote down vote up
private void writeSettings(Settings settings, XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startObject(Fields.SETTINGS);
    settings.toXContent(builder, params);
    builder.endObject();
}
 
Example 18
Source File: AbstractSerializingTestCase.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * Params that have to be provided when calling calling {@link ToXContent#toXContent(XContentBuilder, ToXContent.Params)}
 */
protected ToXContent.Params getToXContentParams() {
    return ToXContent.EMPTY_PARAMS;
}
 
Example 19
Source File: SnapshotShardFailure.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Serializes snapshot failure information into JSON
 *
 * @param snapshotShardFailure snapshot failure information
 * @param builder              XContent builder
 * @param params               additional parameters
 */
public static void toXContent(SnapshotShardFailure snapshotShardFailure, XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startObject();
    snapshotShardFailure.toXContent(builder, params);
    builder.endObject();
}
 
Example 20
Source File: RecoverySource.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * to be overridden by subclasses
 */
public void addAdditionalFields(XContentBuilder builder, ToXContent.Params params) throws IOException {

}