Adds ToXContentFragment (#25771)

* Adds ToXContentFragment

This interface is meant for objects that implement `ToXContent` but are not complete objects. It is basically the opposite of `ToXContentObject`. It means that it will be easier to track the migration of classes over to the fragment/not fragment ToXContent model as it will be clear which classes are not migrated. When no classes directly implement `ToXContent` we can make `ToXContent` package private to be sure that all new classes must implement `ToXContentObject` or `ToXContentFragment`.

* review comments

* more review comments

* javadocs

* iter

* Adds tests

* iter

* adds toString test for aggs

* improves tests following review comments

* iter

* iter
This commit is contained in:
Colin Goodheart-Smithe 2017-08-09 15:53:30 +01:00 committed by GitHub
parent 7d5f00d1d2
commit dfbaf90951
91 changed files with 284 additions and 202 deletions

View File

@ -28,7 +28,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
@ -57,7 +57,7 @@ import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureFieldN
/** /**
* A base class for all elasticsearch exceptions. * A base class for all elasticsearch exceptions.
*/ */
public class ElasticsearchException extends RuntimeException implements ToXContent, Writeable { public class ElasticsearchException extends RuntimeException implements ToXContentFragment, Writeable {
private static final Version UNKNOWN_VERSION_ADDED = Version.fromId(0); private static final Version UNKNOWN_VERSION_ADDED = Version.fromId(0);

View File

@ -30,7 +30,7 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
@ -44,7 +44,7 @@ import static org.elasticsearch.cluster.routing.allocation.AbstractAllocationDec
* or if it is not unassigned, then which nodes it could possibly be relocated to. * or if it is not unassigned, then which nodes it could possibly be relocated to.
* It is an immutable class. * It is an immutable class.
*/ */
public final class ClusterAllocationExplanation implements ToXContent, Writeable { public final class ClusterAllocationExplanation implements ToXContentObject, Writeable {
private final ShardRouting shardRouting; private final ShardRouting shardRouting;
private final DiscoveryNode currentNode; private final DiscoveryNode currentNode;

View File

@ -23,13 +23,13 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
import java.io.IOException; import java.io.IOException;
public class ClusterSearchShardsGroup implements Streamable, ToXContent { public class ClusterSearchShardsGroup implements Streamable, ToXContentObject {
private ShardId shardId; private ShardId shardId;
private ShardRouting[] shards; private ShardRouting[] shards;

View File

@ -21,8 +21,10 @@ package org.elasticsearch.action.admin.cluster.stats;
import com.carrotsearch.hppc.ObjectObjectHashMap; import com.carrotsearch.hppc.ObjectObjectHashMap;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.action.admin.indices.stats.CommonStats; import org.elasticsearch.action.admin.indices.stats.CommonStats;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.cache.query.QueryCacheStats; import org.elasticsearch.index.cache.query.QueryCacheStats;
import org.elasticsearch.index.engine.SegmentsStats; import org.elasticsearch.index.engine.SegmentsStats;
@ -34,7 +36,7 @@ import org.elasticsearch.search.suggest.completion.CompletionStats;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
public class ClusterStatsIndices implements ToXContent { public class ClusterStatsIndices implements ToXContentFragment {
private int indexCount; private int indexCount;
private ShardStats shards; private ShardStats shards;

View File

@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.cluster.stats;
import com.carrotsearch.hppc.ObjectIntHashMap; import com.carrotsearch.hppc.ObjectIntHashMap;
import com.carrotsearch.hppc.cursors.ObjectIntCursor; import com.carrotsearch.hppc.cursors.ObjectIntCursor;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
@ -32,6 +33,7 @@ import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.monitor.fs.FsInfo; import org.elasticsearch.monitor.fs.FsInfo;
import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.monitor.jvm.JvmInfo;
@ -48,7 +50,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
public class ClusterStatsNodes implements ToXContent { public class ClusterStatsNodes implements ToXContentFragment {
private final Counts counts; private final Counts counts;
private final Set<Version> versions; private final Set<Version> versions;
@ -169,7 +171,7 @@ public class ClusterStatsNodes implements ToXContent {
return builder; return builder;
} }
public static class Counts implements ToXContent { public static class Counts implements ToXContentFragment {
static final String COORDINATING_ONLY = "coordinating_only"; static final String COORDINATING_ONLY = "coordinating_only";
private final int total; private final int total;
@ -394,7 +396,7 @@ public class ClusterStatsNodes implements ToXContent {
} }
} }
public static class JvmStats implements ToXContent { public static class JvmStats implements ToXContentFragment {
private final ObjectIntHashMap<JvmVersion> versions; private final ObjectIntHashMap<JvmVersion> versions;
private final long threads; private final long threads;

View File

@ -25,7 +25,7 @@ import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -33,7 +33,7 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
public class ClusterStatsResponse extends BaseNodesResponse<ClusterStatsNodeResponse> implements ToXContent { public class ClusterStatsResponse extends BaseNodesResponse<ClusterStatsNodeResponse> implements ToXContentFragment {
ClusterStatsNodes nodesStats; ClusterStatsNodes nodesStats;
ClusterStatsIndices indicesStats; ClusterStatsIndices indicesStats;

View File

@ -23,13 +23,13 @@ import org.elasticsearch.Version;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.script.StoredScriptSource; import org.elasticsearch.script.StoredScriptSource;
import java.io.IOException; import java.io.IOException;
public class GetStoredScriptResponse extends ActionResponse implements ToXContent { public class GetStoredScriptResponse extends ActionResponse implements ToXContentObject {
private StoredScriptSource source; private StoredScriptSource source;

View File

@ -24,12 +24,13 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
public class DetailAnalyzeResponse implements Streamable, ToXContent { public class DetailAnalyzeResponse implements Streamable, ToXContentFragment {
DetailAnalyzeResponse() { DetailAnalyzeResponse() {
} }
@ -190,7 +191,7 @@ public class DetailAnalyzeResponse implements Streamable, ToXContent {
} }
} }
public static class AnalyzeTokenList implements Streamable, ToXContent { public static class AnalyzeTokenList implements Streamable, ToXContentObject {
private String name; private String name;
private AnalyzeResponse.AnalyzeToken[] tokens; private AnalyzeResponse.AnalyzeToken[] tokens;
@ -216,7 +217,7 @@ public class DetailAnalyzeResponse implements Streamable, ToXContent {
return list; return list;
} }
public XContentBuilder toXContentWithoutObject(XContentBuilder builder, Params params) throws IOException { XContentBuilder toXContentWithoutObject(XContentBuilder builder, Params params) throws IOException {
builder.field(Fields.NAME, this.name); builder.field(Fields.NAME, this.name);
builder.startArray(AnalyzeResponse.Fields.TOKENS); builder.startArray(AnalyzeResponse.Fields.TOKENS);
for (AnalyzeResponse.AnalyzeToken token : tokens) { for (AnalyzeResponse.AnalyzeToken token : tokens) {
@ -229,12 +230,7 @@ public class DetailAnalyzeResponse implements Streamable, ToXContent {
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(); builder.startObject();
builder.field(Fields.NAME, this.name); toXContentWithoutObject(builder, params);
builder.startArray(AnalyzeResponse.Fields.TOKENS);
for (AnalyzeResponse.AnalyzeToken token : tokens) {
token.toXContent(builder, params);
}
builder.endArray();
builder.endObject(); builder.endObject();
return builder; return builder;
} }
@ -265,7 +261,7 @@ public class DetailAnalyzeResponse implements Streamable, ToXContent {
} }
} }
public static class CharFilteredText implements Streamable, ToXContent { public static class CharFilteredText implements Streamable, ToXContentObject {
private String name; private String name;
private String[] texts; private String[] texts;
CharFilteredText() { CharFilteredText() {

View File

@ -24,7 +24,7 @@ import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
@ -38,7 +38,7 @@ import static java.util.Collections.emptyMap;
import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableMap;
/** Response object for {@link GetFieldMappingsRequest} API */ /** Response object for {@link GetFieldMappingsRequest} API */
public class GetFieldMappingsResponse extends ActionResponse implements ToXContent { public class GetFieldMappingsResponse extends ActionResponse implements ToXContentFragment {
private Map<String, Map<String, Map<String, FieldMappingMetaData>>> mappings = emptyMap(); private Map<String, Map<String, Map<String, FieldMappingMetaData>>> mappings = emptyMap();
@ -92,7 +92,7 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
return builder; return builder;
} }
public static class FieldMappingMetaData implements ToXContent { public static class FieldMappingMetaData implements ToXContentFragment {
public static final FieldMappingMetaData NULL = new FieldMappingMetaData("", BytesArray.EMPTY); public static final FieldMappingMetaData NULL = new FieldMappingMetaData("", BytesArray.EMPTY);
private String fullName; private String fullName;

View File

@ -29,7 +29,7 @@ import org.elasticsearch.action.support.broadcast.BroadcastResponse;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.engine.Segment; import org.elasticsearch.index.engine.Segment;
@ -39,11 +39,11 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Locale;
public class IndicesSegmentResponse extends BroadcastResponse implements ToXContent { public class IndicesSegmentResponse extends BroadcastResponse implements ToXContentFragment {
private ShardSegments[] shards; private ShardSegments[] shards;

View File

@ -34,6 +34,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -49,7 +50,7 @@ import static org.elasticsearch.action.admin.indices.shards.IndicesShardStoresRe
* Consists of {@link StoreStatus}s for requested indices grouped by * Consists of {@link StoreStatus}s for requested indices grouped by
* indices and shard ids and a list of encountered node {@link Failure}s * indices and shard ids and a list of encountered node {@link Failure}s
*/ */
public class IndicesShardStoresResponse extends ActionResponse implements ToXContent { public class IndicesShardStoresResponse extends ActionResponse implements ToXContentFragment {
/** /**
* Shard store information from a node * Shard store information from a node

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.cache.query.QueryCacheStats; import org.elasticsearch.index.cache.query.QueryCacheStats;
import org.elasticsearch.index.cache.request.RequestCacheStats; import org.elasticsearch.index.cache.request.RequestCacheStats;
@ -50,7 +51,7 @@ import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Stream; import java.util.stream.Stream;
public class CommonStats implements Writeable, ToXContent { public class CommonStats implements Writeable, ToXContentFragment {
@Nullable @Nullable
public DocsStats docs; public DocsStats docs;

View File

@ -24,7 +24,7 @@ import org.elasticsearch.action.support.broadcast.BroadcastResponse;
import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -38,7 +38,7 @@ import java.util.Set;
import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableMap;
public class IndicesStatsResponse extends BroadcastResponse implements ToXContent { public class IndicesStatsResponse extends BroadcastResponse implements ToXContentFragment {
private ShardStats[] shards; private ShardStats[] shards;

View File

@ -34,7 +34,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.StatusToXContentObject; import org.elasticsearch.common.xcontent.StatusToXContentObject;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.seqno.SequenceNumbersService; import org.elasticsearch.index.seqno.SequenceNumbersService;
@ -160,7 +160,7 @@ public class BulkItemResponse implements Streamable, StatusToXContentObject {
/** /**
* Represents a failure. * Represents a failure.
*/ */
public static class Failure implements Writeable, ToXContent { public static class Failure implements Writeable, ToXContentFragment {
static final String INDEX_FIELD = "index"; static final String INDEX_FIELD = "index";
static final String TYPE_FIELD = "type"; static final String TYPE_FIELD = "type";
static final String ID_FIELD = "id"; static final String ID_FIELD = "id";

View File

@ -22,20 +22,20 @@ package org.elasticsearch.action.fieldcaps;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
/** /**
* Describes the capabilities of a field optionally merged across multiple indices. * Describes the capabilities of a field optionally merged across multiple indices.
*/ */
public class FieldCapabilities implements Writeable, ToXContent { public class FieldCapabilities implements Writeable, ToXContentObject {
private final String name; private final String name;
private final String type; private final String type;
private final boolean isSearchable; private final boolean isSearchable;

View File

@ -23,7 +23,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -34,7 +34,7 @@ import java.util.Map;
/** /**
* Response for {@link FieldCapabilitiesRequest} requests. * Response for {@link FieldCapabilitiesRequest} requests.
*/ */
public class FieldCapabilitiesResponse extends ActionResponse implements ToXContent { public class FieldCapabilitiesResponse extends ActionResponse implements ToXContentFragment {
private Map<String, Map<String, FieldCapabilities>> responseMap; private Map<String, Map<String, FieldCapabilities>> responseMap;
private List<FieldCapabilitiesIndexResponse> indexResponses; private List<FieldCapabilitiesIndexResponse> indexResponses;

View File

@ -20,7 +20,7 @@
package org.elasticsearch.action.search; package org.elasticsearch.action.search;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.Aggregations;
@ -40,7 +40,7 @@ import java.util.Map;
* to parse aggregations into, which are not serializable. This is the common part that can be * to parse aggregations into, which are not serializable. This is the common part that can be
* shared between core and client. * shared between core and client.
*/ */
public class SearchResponseSections implements ToXContent { public class SearchResponseSections implements ToXContentFragment {
protected final SearchHits hits; protected final SearchHits hits;
protected final Aggregations aggregations; protected final Aggregations aggregations;

View File

@ -20,17 +20,16 @@
package org.elasticsearch.cluster; package org.elasticsearch.cluster;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.ToXContent.Params;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* ClusterInfo is an object representing a map of nodes to {@link DiskUsage} * ClusterInfo is an object representing a map of nodes to {@link DiskUsage}
@ -38,7 +37,7 @@ import java.util.Map;
* <code>InternalClusterInfoService.shardIdentifierFromRouting(String)</code> * <code>InternalClusterInfoService.shardIdentifierFromRouting(String)</code>
* for the key used in the shardSizes map * for the key used in the shardSizes map
*/ */
public class ClusterInfo implements ToXContent, Writeable { public class ClusterInfo implements ToXContentFragment, Writeable {
private final ImmutableOpenMap<String, DiskUsage> leastAvailableSpaceUsage; private final ImmutableOpenMap<String, DiskUsage> leastAvailableSpaceUsage;
private final ImmutableOpenMap<String, DiskUsage> mostAvailableSpaceUsage; private final ImmutableOpenMap<String, DiskUsage> mostAvailableSpaceUsage;
final ImmutableOpenMap<String, Long> shardSizes; final ImmutableOpenMap<String, Long> shardSizes;
@ -117,13 +116,13 @@ public class ClusterInfo implements ToXContent, Writeable {
builder.startObject(c.key); { // node builder.startObject(c.key); { // node
builder.field("node_name", c.value.getNodeName()); builder.field("node_name", c.value.getNodeName());
builder.startObject("least_available"); { builder.startObject("least_available"); {
c.value.toShortXContent(builder, params); c.value.toShortXContent(builder);
} }
builder.endObject(); // end "least_available" builder.endObject(); // end "least_available"
builder.startObject("most_available"); { builder.startObject("most_available"); {
DiskUsage most = this.mostAvailableSpaceUsage.get(c.key); DiskUsage most = this.mostAvailableSpaceUsage.get(c.key);
if (most != null) { if (most != null) {
most.toShortXContent(builder, params); most.toShortXContent(builder);
} }
} }
builder.endObject(); // end "most_available" builder.endObject(); // end "most_available"

View File

@ -22,6 +22,7 @@ package org.elasticsearch.cluster;
import com.carrotsearch.hppc.cursors.IntObjectCursor; import com.carrotsearch.hppc.cursors.IntObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.cluster.block.ClusterBlock; import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData;
@ -50,6 +51,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.Discovery;
@ -85,7 +87,7 @@ import java.util.Set;
* throws the {@link IncompatibleClusterStateVersionException}, which causes the publishing mechanism to send * throws the {@link IncompatibleClusterStateVersionException}, which causes the publishing mechanism to send
* a full version of the cluster state to the node on which this exception was thrown. * a full version of the cluster state to the node on which this exception was thrown.
*/ */
public class ClusterState implements ToXContent, Diffable<ClusterState> { public class ClusterState implements ToXContentFragment, Diffable<ClusterState> {
public static final ClusterState EMPTY_STATE = builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).build(); public static final ClusterState EMPTY_STATE = builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).build();

View File

@ -24,7 +24,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -33,7 +33,7 @@ import java.util.Objects;
/** /**
* Encapsulation class used to represent the amount of disk used on a node. * Encapsulation class used to represent the amount of disk used on a node.
*/ */
public class DiskUsage implements ToXContent, Writeable { public class DiskUsage implements ToXContentFragment, Writeable {
final String nodeId; final String nodeId;
final String nodeName; final String nodeName;
final String path; final String path;
@ -73,7 +73,7 @@ public class DiskUsage implements ToXContent, Writeable {
return Math.round(pct * 10.0) / 10.0; return Math.round(pct * 10.0) / 10.0;
} }
public XContentBuilder toShortXContent(XContentBuilder builder, Params params) throws IOException { XContentBuilder toShortXContent(XContentBuilder builder) throws IOException {
builder.field("path", this.path); builder.field("path", this.path);
builder.byteSizeField("total_bytes", "total", this.totalBytes); builder.byteSizeField("total_bytes", "total", this.totalBytes);
builder.byteSizeField("used_bytes", "used", this.getUsedBytes()); builder.byteSizeField("used_bytes", "used", this.getUsedBytes());
@ -86,7 +86,7 @@ public class DiskUsage implements ToXContent, Writeable {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("node_id", this.nodeId); builder.field("node_id", this.nodeId);
builder.field("node_name", this.nodeName); builder.field("node_name", this.nodeName);
builder = toShortXContent(builder, params); builder = toShortXContent(builder);
return builder; return builder;
} }

View File

@ -23,7 +23,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
@ -32,7 +32,7 @@ import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Locale; import java.util.Locale;
public class ClusterBlock implements Streamable, ToXContent { public class ClusterBlock implements Streamable, ToXContentFragment {
private int id; private int id;

View File

@ -25,7 +25,7 @@ import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -34,7 +34,7 @@ import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
public final class ClusterIndexHealth implements Iterable<ClusterShardHealth>, Writeable, ToXContent { public final class ClusterIndexHealth implements Iterable<ClusterShardHealth>, Writeable, ToXContentFragment {
private final String index; private final String index;
private final int numberOfShards; private final int numberOfShards;

View File

@ -23,6 +23,7 @@ import com.carrotsearch.hppc.LongArrayList;
import com.carrotsearch.hppc.cursors.IntObjectCursor; import com.carrotsearch.hppc.cursors.IntObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diff;
@ -45,6 +46,7 @@ import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.loader.SettingsLoader; import org.elasticsearch.common.settings.loader.SettingsLoader;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
@ -75,7 +77,7 @@ import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.OR;
import static org.elasticsearch.common.settings.Settings.readSettingsFromStream; import static org.elasticsearch.common.settings.Settings.readSettingsFromStream;
import static org.elasticsearch.common.settings.Settings.writeSettingsToStream; import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
public class IndexMetaData implements Diffable<IndexMetaData>, ToXContent { public class IndexMetaData implements Diffable<IndexMetaData>, ToXContentFragment {
/** /**
* This class will be removed in v7.0 * This class will be removed in v7.0

View File

@ -22,6 +22,7 @@ package org.elasticsearch.cluster.metadata;
import com.carrotsearch.hppc.ObjectHashSet; import com.carrotsearch.hppc.ObjectHashSet;
import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.CollectionUtil; import org.apache.lucene.util.CollectionUtil;
import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diff;
@ -45,6 +46,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.loader.SettingsLoader; import org.elasticsearch.common.settings.loader.SettingsLoader;
import org.elasticsearch.common.xcontent.NamedXContentRegistry.UnknownNamedObjectException; import org.elasticsearch.common.xcontent.NamedXContentRegistry.UnknownNamedObjectException;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -70,7 +72,7 @@ import java.util.TreeMap;
import static org.elasticsearch.common.settings.Settings.readSettingsFromStream; import static org.elasticsearch.common.settings.Settings.readSettingsFromStream;
import static org.elasticsearch.common.settings.Settings.writeSettingsToStream; import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, ToXContent { public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, ToXContentFragment {
private static final Logger logger = Loggers.getLogger(MetaData.class); private static final Logger logger = Loggers.getLogger(MetaData.class);

View File

@ -26,7 +26,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
@ -42,7 +42,7 @@ import java.util.function.Predicate;
/** /**
* A discovery node represents a node that is part of the cluster. * A discovery node represents a node that is part of the cluster.
*/ */
public class DiscoveryNode implements Writeable, ToXContent { public class DiscoveryNode implements Writeable, ToXContentFragment {
public static boolean nodeRequiresLocalStorage(Settings settings) { public static boolean nodeRequiresLocalStorage(Settings settings) {
boolean localStorageEnable = Node.NODE_LOCAL_STORAGE_SETTING.get(settings); boolean localStorageEnable = Node.NODE_LOCAL_STORAGE_SETTING.get(settings);

View File

@ -26,7 +26,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -42,7 +42,7 @@ import java.util.Objects;
* relocationId. Once relocation is done, the new allocation id is set to the relocationId. This is similar * relocationId. Once relocation is done, the new allocation id is set to the relocationId. This is similar
* behavior to how ShardRouting#currentNodeId is used. * behavior to how ShardRouting#currentNodeId is used.
*/ */
public class AllocationId implements ToXContent, Writeable { public class AllocationId implements ToXContentObject, Writeable {
private static final String ID_KEY = "id"; private static final String ID_KEY = "id";
private static final String RELOCATION_ID_KEY = "relocation_id"; private static final String RELOCATION_ID_KEY = "relocation_id";

View File

@ -25,7 +25,7 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -38,7 +38,7 @@ import java.util.stream.Collectors;
/** /**
* An abstract class for representing various types of allocation decisions. * An abstract class for representing various types of allocation decisions.
*/ */
public abstract class AbstractAllocationDecision implements ToXContent, Writeable { public abstract class AbstractAllocationDecision implements ToXContentFragment, Writeable {
@Nullable @Nullable
protected final DiscoveryNode targetNode; protected final DiscoveryNode targetNode;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.common.document;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.get.GetResult; import org.elasticsearch.index.get.GetResult;
@ -44,7 +44,7 @@ import static org.elasticsearch.common.xcontent.XContentParserUtils.parseStoredF
* @see SearchHit * @see SearchHit
* @see GetResult * @see GetResult
*/ */
public class DocumentField implements Streamable, ToXContent, Iterable<Object> { public class DocumentField implements Streamable, ToXContentFragment, Iterable<Object> {
private String name; private String name;
private List<Object> values; private List<Object> values;

View File

@ -22,6 +22,7 @@ package org.elasticsearch.common.geo.builders;
import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.GeometryFactory;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.Assertions; import org.elasticsearch.Assertions;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
@ -31,7 +32,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.unit.DistanceUnit.Distance; import org.elasticsearch.common.unit.DistanceUnit.Distance;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -260,7 +261,7 @@ public abstract class ShapeBuilder extends ToXContentToBytes implements NamedWri
* Can either be a leaf node consisting of a Coordinate, or a parent with * Can either be a leaf node consisting of a Coordinate, or a parent with
* children * children
*/ */
protected static class CoordinateNode implements ToXContent { protected static class CoordinateNode implements ToXContentObject {
protected final Coordinate coordinate; protected final Coordinate coordinate;
protected final List<CoordinateNode> children; protected final List<CoordinateNode> children;

View File

@ -22,7 +22,7 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -35,7 +35,7 @@ import java.util.Objects;
* parsing and conversion from similarities to edit distances * parsing and conversion from similarities to edit distances
* etc. * etc.
*/ */
public final class Fuzziness implements ToXContent, Writeable { public final class Fuzziness implements ToXContentFragment, Writeable {
public static final String X_FIELD_NAME = "fuzziness"; public static final String X_FIELD_NAME = "fuzziness";
public static final Fuzziness ZERO = new Fuzziness(0); public static final Fuzziness ZERO = new Fuzziness(0);
@ -124,15 +124,7 @@ public final class Fuzziness implements ToXContent, Writeable {
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return toXContent(builder, params, true); builder.field(X_FIELD_NAME, fuzziness);
}
public XContentBuilder toXContent(XContentBuilder builder, Params params, boolean includeFieldName) throws IOException {
if (includeFieldName) {
builder.field(X_FIELD_NAME, fuzziness);
} else {
builder.value(fuzziness);
}
return builder; return builder;
} }

View File

@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common.xcontent;
/**
* An interface allowing to transfer an object to "XContent" using an
* {@link XContentBuilder}. The difference between {@link ToXContentFragment}
* and {@link ToXContentObject} is that the former outputs a fragment that
* requires to start and end a new anonymous object externally, while the latter
* guarantees that what gets printed out is fully valid syntax without any
* external addition.
*/
public interface ToXContentFragment extends ToXContent {
@Override
default boolean isFragment() {
return true;
}
}

View File

@ -20,10 +20,12 @@
package org.elasticsearch.common.xcontent; package org.elasticsearch.common.xcontent;
/** /**
* An interface allowing to transfer an object to "XContent" using an {@link XContentBuilder}. * An interface allowing to transfer an object to "XContent" using an
* The difference between {@link ToXContent} and {@link ToXContentObject} is that the former may output a fragment that * {@link XContentBuilder}. The difference between {@link ToXContentFragment}
* requires to start and end a new anonymous object externally, while the latter guarantees that what gets printed * and {@link ToXContentObject} is that the former outputs a fragment that
* out is fully valid syntax without any external addition. * requires to start and end a new anonymous object externally, while the latter
* guarantees that what gets printed out is fully valid syntax without any
* external addition.
*/ */
public interface ToXContentObject extends ToXContent { public interface ToXContentObject extends ToXContent {

View File

@ -23,13 +23,13 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.discovery.zen.PendingClusterStateStats; import org.elasticsearch.discovery.zen.PendingClusterStateStats;
import java.io.IOException; import java.io.IOException;
public class DiscoveryStats implements Writeable, ToXContent { public class DiscoveryStats implements Writeable, ToXContentFragment {
@Nullable @Nullable
private final PendingClusterStateStats queueStats; private final PendingClusterStateStats queueStats;

View File

@ -24,12 +24,12 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.transport.BoundTransportAddress; import org.elasticsearch.common.transport.BoundTransportAddress;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
public class HttpInfo implements Writeable, ToXContent { public class HttpInfo implements Writeable, ToXContentFragment {
private final BoundTransportAddress address; private final BoundTransportAddress address;
private final long maxContentLength; private final long maxContentLength;

View File

@ -22,12 +22,12 @@ package org.elasticsearch.http;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
public class HttpStats implements Writeable, ToXContent { public class HttpStats implements Writeable, ToXContentFragment {
private final long serverOpen; private final long serverOpen;
private final long totalOpen; private final long totalOpen;

View File

@ -25,7 +25,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -35,7 +35,7 @@ import java.util.Objects;
/** /**
* A value class representing the basic required properties of an Elasticsearch index. * A value class representing the basic required properties of an Elasticsearch index.
*/ */
public class Index implements Writeable, ToXContent { public class Index implements Writeable, ToXContentObject {
public static final Index[] EMPTY_ARRAY = new Index[0]; public static final Index[] EMPTY_ARRAY = new Index[0];
private static final String INDEX_UUID_KEY = "index_uuid"; private static final String INDEX_UUID_KEY = "index_uuid";

View File

@ -24,7 +24,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -32,7 +32,7 @@ import java.util.Base64;
import java.util.Map; import java.util.Map;
/** a class the returns dynamic information with respect to the last commit point of this shard */ /** a class the returns dynamic information with respect to the last commit point of this shard */
public final class CommitStats implements Streamable, ToXContent { public final class CommitStats implements Streamable, ToXContentFragment {
private Map<String, String> userData; private Map<String, String> userData;
private long generation; private long generation;

View File

@ -25,13 +25,13 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
public class FieldDataStats implements Streamable, ToXContent { public class FieldDataStats implements Streamable, ToXContentFragment {
private static final String FIELDDATA = "fielddata"; private static final String FIELDDATA = "fielddata";
private static final String MEMORY_SIZE = "memory_size"; private static final String MEMORY_SIZE = "memory_size";

View File

@ -23,12 +23,12 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
public class FlushStats implements Streamable, ToXContent { public class FlushStats implements Streamable, ToXContentFragment {
private long total; private long total;

View File

@ -23,12 +23,12 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
public class GetStats implements Streamable, ToXContent { public class GetStats implements Streamable, ToXContentFragment {
private long existsCount; private long existsCount;
private long existsTimeInMillis; private long existsTimeInMillis;

View File

@ -28,6 +28,7 @@ import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexSettings;
@ -47,7 +48,7 @@ import java.util.Objects;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
public class DocumentMapper implements ToXContent { public class DocumentMapper implements ToXContentFragment {
public static class Builder { public static class Builder {

View File

@ -23,7 +23,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -34,7 +34,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
public class DynamicTemplate implements ToXContent { public class DynamicTemplate implements ToXContentObject {
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(DynamicTemplate.class)); private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(DynamicTemplate.class));

View File

@ -21,7 +21,7 @@ package org.elasticsearch.index.mapper;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.index.analysis.IndexAnalyzers; import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.similarity.SimilarityProvider; import org.elasticsearch.index.similarity.SimilarityProvider;
@ -31,7 +31,7 @@ import java.util.Objects;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public abstract class Mapper implements ToXContent, Iterable<Mapper> { public abstract class Mapper implements ToXContentFragment, Iterable<Mapper> {
public static class BuilderContext { public static class BuilderContext {
private final Settings indexSettings; private final Settings indexSettings;

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -38,7 +39,7 @@ import static java.util.Collections.unmodifiableMap;
* Wrapper around everything that defines a mapping, without references to * Wrapper around everything that defines a mapping, without references to
* utility classes like MapperService, ... * utility classes like MapperService, ...
*/ */
public final class Mapping implements ToXContent { public final class Mapping implements ToXContentFragment {
final Version indexCreated; final Version indexCreated;
final RootObjectMapper root; final RootObjectMapper root;

View File

@ -24,12 +24,12 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
public class MergeStats implements Streamable, ToXContent { public class MergeStats implements Streamable, ToXContentFragment {
private long total; private long total;
private long totalTimeInMillis; private long totalTimeInMillis;

View File

@ -45,7 +45,7 @@ import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.lucene.search.MoreLikeThisQuery; import org.elasticsearch.common.lucene.search.MoreLikeThisQuery;
import org.elasticsearch.common.lucene.search.XMoreLikeThis; import org.elasticsearch.common.lucene.search.XMoreLikeThis;
import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -142,7 +142,7 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
/** /**
* A single item to be used for a {@link MoreLikeThisQueryBuilder}. * A single item to be used for a {@link MoreLikeThisQueryBuilder}.
*/ */
public static final class Item implements ToXContent, Writeable { public static final class Item implements ToXContentObject, Writeable {
public static final Item[] EMPTY_ARRAY = new Item[0]; public static final Item[] EMPTY_ARRAY = new Item[0];
public interface Field { public interface Field {

View File

@ -29,7 +29,7 @@ import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.lucene.search.function.CombineFunction; import org.elasticsearch.common.lucene.search.function.CombineFunction;
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
import org.elasticsearch.common.lucene.search.function.ScoreFunction; import org.elasticsearch.common.lucene.search.function.ScoreFunction;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -328,7 +328,7 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder<FunctionScor
* Function to be associated with an optional filter, meaning it will be executed only for the documents * Function to be associated with an optional filter, meaning it will be executed only for the documents
* that match the given filter. * that match the given filter.
*/ */
public static class FilterFunctionBuilder implements ToXContent, Writeable { public static class FilterFunctionBuilder implements ToXContentObject, Writeable {
private final QueryBuilder filter; private final QueryBuilder filter;
private final ScoreFunctionBuilder<?> scoreFunction; private final ScoreFunctionBuilder<?> scoreFunction;

View File

@ -25,7 +25,7 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -40,7 +40,7 @@ import static org.elasticsearch.common.unit.TimeValue.timeValueNanos;
/** /**
* Response used for actions that index many documents using a scroll request. * Response used for actions that index many documents using a scroll request.
*/ */
public class BulkByScrollResponse extends ActionResponse implements ToXContent { public class BulkByScrollResponse extends ActionResponse implements ToXContentFragment {
private TimeValue took; private TimeValue took;
private BulkByScrollTask.Status status; private BulkByScrollTask.Status status;
private List<Failure> bulkFailures; private List<Failure> bulkFailures;

View File

@ -22,12 +22,12 @@ package org.elasticsearch.index.shard;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
public class DocsStats implements Streamable, ToXContent { public class DocsStats implements Streamable, ToXContentFragment {
long count = 0; long count = 0;
long deleted = 0; long deleted = 0;

View File

@ -19,20 +19,20 @@
package org.elasticsearch.index.shard; package org.elasticsearch.index.shard;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class IndexingStats implements Streamable, ToXContent { public class IndexingStats implements Streamable, ToXContentFragment {
public static class Stats implements Streamable, ToXContent { public static class Stats implements Streamable, ToXContent {

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.store.StoreFileMetaData; import org.elasticsearch.index.store.StoreFileMetaData;
@ -39,7 +40,7 @@ import java.util.List;
/** /**
* Shard snapshot metadata * Shard snapshot metadata
*/ */
public class BlobStoreIndexShardSnapshot implements ToXContent { public class BlobStoreIndexShardSnapshot implements ToXContentFragment {
/** /**
* Information about snapshotted file * Information about snapshotted file

View File

@ -21,7 +21,7 @@ package org.elasticsearch.index.snapshots.blobstore;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo;
@ -42,7 +42,7 @@ import static java.util.Collections.unmodifiableMap;
* This class is used to find files that were already snapshotted and clear out files that no longer referenced by any * This class is used to find files that were already snapshotted and clear out files that no longer referenced by any
* snapshots * snapshots
*/ */
public class BlobStoreIndexShardSnapshots implements Iterable<SnapshotFiles>, ToXContent { public class BlobStoreIndexShardSnapshots implements Iterable<SnapshotFiles>, ToXContentFragment {
private final List<SnapshotFiles> shardSnapshots; private final List<SnapshotFiles> shardSnapshots;
private final Map<String, FileInfo> files; private final Map<String, FileInfo> files;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.indices.breaker;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -30,7 +30,7 @@ import java.io.IOException;
/** /**
* Stats class encapsulating all of the different circuit breaker stats * Stats class encapsulating all of the different circuit breaker stats
*/ */
public class AllCircuitBreakerStats implements Writeable, ToXContent { public class AllCircuitBreakerStats implements Writeable, ToXContentFragment {
private final CircuitBreakerStats[] allStats; private final CircuitBreakerStats[] allStats;

View File

@ -23,7 +23,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -32,7 +32,7 @@ import java.util.Locale;
/** /**
* Class encapsulating stats about the circuit breaker * Class encapsulating stats about the circuit breaker
*/ */
public class CircuitBreakerStats implements Writeable, ToXContent { public class CircuitBreakerStats implements Writeable, ToXContentObject {
private final String name; private final String name;
private final long limit; private final long limit;

View File

@ -28,6 +28,8 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
@ -552,7 +554,7 @@ public class RecoveryState implements ToXContent, Streamable {
} }
} }
public static class File implements ToXContent, Streamable { public static class File implements ToXContentObject, Streamable {
private String name; private String name;
private long length; private long length;
private long recovered; private long recovered;
@ -663,7 +665,7 @@ public class RecoveryState implements ToXContent, Streamable {
} }
} }
public static class Index extends Timer implements ToXContent, Streamable { public static class Index extends Timer implements ToXContentFragment, Streamable {
private Map<String, File> fileDetails = new HashMap<>(); private Map<String, File> fileDetails = new HashMap<>();

View File

@ -22,7 +22,7 @@ package org.elasticsearch.ingest;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -31,7 +31,7 @@ import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
public class IngestInfo implements Writeable, ToXContent { public class IngestInfo implements Writeable, ToXContentFragment {
private final Set<ProcessorInfo> processors; private final Set<ProcessorInfo> processors;

View File

@ -23,6 +23,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -30,7 +31,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class IngestStats implements Writeable, ToXContent { public class IngestStats implements Writeable, ToXContentFragment {
private final Stats totalStats; private final Stats totalStats;
private final Map<String, Stats> statsPerPipeline; private final Map<String, Stats> statsPerPipeline;

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -35,7 +36,7 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
public class FsInfo implements Iterable<FsInfo.Path>, Writeable, ToXContent { public class FsInfo implements Iterable<FsInfo.Path>, Writeable, ToXContentFragment {
public static class Path implements Writeable, ToXContent { public static class Path implements Writeable, ToXContent {
@ -178,7 +179,7 @@ public class FsInfo implements Iterable<FsInfo.Path>, Writeable, ToXContent {
} }
} }
public static class DeviceStats implements Writeable, ToXContent { public static class DeviceStats implements Writeable, ToXContentFragment {
final int majorDeviceNumber; final int majorDeviceNumber;
final int minorDeviceNumber; final int minorDeviceNumber;
@ -313,7 +314,7 @@ public class FsInfo implements Iterable<FsInfo.Path>, Writeable, ToXContent {
} }
public static class IoStats implements Writeable, ToXContent { public static class IoStats implements Writeable, ToXContentFragment {
private static final String OPERATIONS = "operations"; private static final String OPERATIONS = "operations";
private static final String READ_OPERATIONS = "read_operations"; private static final String READ_OPERATIONS = "read_operations";

View File

@ -23,7 +23,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -39,7 +39,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class JvmInfo implements Writeable, ToXContent { public class JvmInfo implements Writeable, ToXContentFragment {
private static JvmInfo INSTANCE; private static JvmInfo INSTANCE;

View File

@ -24,7 +24,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -44,7 +44,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class JvmStats implements Writeable, ToXContent { public class JvmStats implements Writeable, ToXContentFragment {
private static final RuntimeMXBean runtimeMXBean; private static final RuntimeMXBean runtimeMXBean;
private static final MemoryMXBean memoryMXBean; private static final MemoryMXBean memoryMXBean;

View File

@ -25,6 +25,8 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -125,7 +127,7 @@ public class OsStats implements Writeable, ToXContent {
return builder; return builder;
} }
public static class Cpu implements Writeable, ToXContent { public static class Cpu implements Writeable, ToXContentFragment {
private final short percent; private final short percent;
private final double[] loadAverage; private final double[] loadAverage;
@ -229,7 +231,7 @@ public class OsStats implements Writeable, ToXContent {
} }
} }
public static class Mem implements Writeable, ToXContent { public static class Mem implements Writeable, ToXContentFragment {
private final long total; private final long total;
private final long free; private final long free;
@ -286,7 +288,7 @@ public class OsStats implements Writeable, ToXContent {
/** /**
* Encapsulates basic cgroup statistics. * Encapsulates basic cgroup statistics.
*/ */
public static class Cgroup implements Writeable, ToXContent { public static class Cgroup implements Writeable, ToXContentObject {
private final String cpuAcctControlGroup; private final String cpuAcctControlGroup;
private final long cpuAcctUsageNanos; private final long cpuAcctUsageNanos;
@ -415,7 +417,7 @@ public class OsStats implements Writeable, ToXContent {
/** /**
* Encapsulates CPU time statistics. * Encapsulates CPU time statistics.
*/ */
public static class CpuStat implements Writeable, ToXContent { public static class CpuStat implements Writeable, ToXContentFragment {
private final long numberOfElapsedPeriods; private final long numberOfElapsedPeriods;
private final long numberOfTimesThrottled; private final long numberOfTimesThrottled;

View File

@ -23,6 +23,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
@ -32,7 +33,7 @@ import java.util.Objects;
/** /**
* Represents a single snapshotted index in the repository. * Represents a single snapshotted index in the repository.
*/ */
public final class IndexId implements Writeable, ToXContent { public final class IndexId implements Writeable, ToXContentObject {
protected static final String NAME = "name"; protected static final String NAME = "name";
protected static final String ID = "id"; protected static final String ID = "id";

View File

@ -19,10 +19,10 @@
package org.elasticsearch.search.aggregations; package org.elasticsearch.search.aggregations;
import org.elasticsearch.action.support.ToXContentToBytes;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.NamedWriteable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryRewriteContext; import org.elasticsearch.index.query.QueryRewriteContext;
import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.SearchContext;
@ -35,8 +35,7 @@ import java.util.Map;
* A factory that knows how to create an {@link Aggregator} of a specific type. * A factory that knows how to create an {@link Aggregator} of a specific type.
*/ */
public abstract class AggregationBuilder public abstract class AggregationBuilder
extends ToXContentToBytes implements NamedWriteable, ToXContentFragment, BaseAggregationBuilder {
implements NamedWriteable, ToXContent, BaseAggregationBuilder {
protected final String name; protected final String name;
protected AggregatorFactories.Builder factoriesBuilder = AggregatorFactories.builder(); protected AggregatorFactories.Builder factoriesBuilder = AggregatorFactories.builder();
@ -139,4 +138,9 @@ public abstract class AggregationBuilder
public static final class CommonFields extends ParseField.CommonFields { public static final class CommonFields extends ParseField.CommonFields {
public static final ParseField VALUE_TYPE = new ParseField("value_type"); public static final ParseField VALUE_TYPE = new ParseField("value_type");
} }
@Override
public String toString() {
return Strings.toString(this);
}
} }

View File

@ -20,7 +20,7 @@ package org.elasticsearch.search.aggregations;
import org.apache.lucene.util.SetOnce; import org.apache.lucene.util.SetOnce;
import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -40,7 +40,7 @@ import static org.elasticsearch.common.xcontent.XContentParserUtils.parseTypedKe
/** /**
* Represents a set of {@link Aggregation}s * Represents a set of {@link Aggregation}s
*/ */
public class Aggregations implements Iterable<Aggregation>, ToXContent { public class Aggregations implements Iterable<Aggregation>, ToXContentFragment {
public static final String AGGREGATIONS_FIELD = "aggregations"; public static final String AGGREGATIONS_FIELD = "aggregations";

View File

@ -23,7 +23,6 @@ import org.elasticsearch.common.io.stream.NamedWriteable;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
@ -38,7 +37,7 @@ import java.util.Objects;
/** /**
* An internal implementation of {@link Aggregation}. Serves as a base class for all aggregation implementations. * An internal implementation of {@link Aggregation}. Serves as a base class for all aggregation implementations.
*/ */
public abstract class InternalAggregation implements Aggregation, ToXContent, NamedWriteable { public abstract class InternalAggregation implements Aggregation, NamedWriteable {
public static class ReduceContext { public static class ReduceContext {

View File

@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext; import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext;
import java.io.IOException; import java.io.IOException;
@ -35,7 +34,7 @@ import static java.util.Collections.emptyMap;
/** /**
* An internal implementation of {@link Aggregations}. * An internal implementation of {@link Aggregations}.
*/ */
public final class InternalAggregations extends Aggregations implements ToXContent, Streamable { public final class InternalAggregations extends Aggregations implements Streamable {
public static final InternalAggregations EMPTY = new InternalAggregations(); public static final InternalAggregations EMPTY = new InternalAggregations();

View File

@ -28,7 +28,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.xcontent.ObjectParser.NamedObjectParser; import org.elasticsearch.common.xcontent.ObjectParser.NamedObjectParser;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
@ -63,7 +63,7 @@ public class AdjacencyMatrixAggregator extends BucketsAggregator {
public static final ParseField FILTERS_FIELD = new ParseField("filters"); public static final ParseField FILTERS_FIELD = new ParseField("filters");
protected static class KeyedFilter implements Writeable, ToXContent { protected static class KeyedFilter implements Writeable, ToXContentFragment {
private final String key; private final String key;
private final QueryBuilder filter; private final QueryBuilder filter;

View File

@ -27,7 +27,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.Aggregator;
@ -52,7 +52,7 @@ public class FiltersAggregator extends BucketsAggregator {
public static final ParseField OTHER_BUCKET_FIELD = new ParseField("other_bucket"); public static final ParseField OTHER_BUCKET_FIELD = new ParseField("other_bucket");
public static final ParseField OTHER_BUCKET_KEY_FIELD = new ParseField("other_bucket_key"); public static final ParseField OTHER_BUCKET_KEY_FIELD = new ParseField("other_bucket_key");
public static class KeyedFilter implements Writeable, ToXContent { public static class KeyedFilter implements Writeable, ToXContentFragment {
private final String key; private final String key;
private final QueryBuilder filter; private final QueryBuilder filter;

View File

@ -27,7 +27,7 @@ import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.rounding.Rounding; import org.elasticsearch.common.rounding.Rounding;
import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ObjectParser.ValueType; import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.common.xcontent.XContentParser.Token;
@ -40,7 +40,7 @@ import java.util.Objects;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
public class ExtendedBounds implements ToXContent, Writeable { public class ExtendedBounds implements ToXContentFragment, Writeable {
static final ParseField EXTENDED_BOUNDS_FIELD = Histogram.EXTENDED_BOUNDS_FIELD; static final ParseField EXTENDED_BOUNDS_FIELD = Histogram.EXTENDED_BOUNDS_FIELD;
static final ParseField MIN_FIELD = new ParseField("min"); static final ParseField MIN_FIELD = new ParseField("min");
static final ParseField MAX_FIELD = new ParseField("max"); static final ParseField MAX_FIELD = new ParseField("max");

View File

@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.bucket.significant;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.Aggregations;
@ -42,7 +41,7 @@ import java.util.Objects;
* Result of the significant terms aggregation. * Result of the significant terms aggregation.
*/ */
public abstract class InternalSignificantTerms<A extends InternalSignificantTerms<A, B>, B extends InternalSignificantTerms.Bucket<B>> public abstract class InternalSignificantTerms<A extends InternalSignificantTerms<A, B>, B extends InternalSignificantTerms.Bucket<B>>
extends InternalMultiBucketAggregation<A, B> implements SignificantTerms, ToXContent { extends InternalMultiBucketAggregation<A, B> implements SignificantTerms {
public static final String SCORE = "score"; public static final String SCORE = "score";
public static final String BG_COUNT = "bg_count"; public static final String BG_COUNT = "bg_count";

View File

@ -41,7 +41,7 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.DocValueFormat;
@ -57,7 +57,7 @@ import java.util.TreeSet;
* Defines the include/exclude regular expression filtering for string terms aggregation. In this filtering logic, * Defines the include/exclude regular expression filtering for string terms aggregation. In this filtering logic,
* exclusion has precedence, where the {@code include} is evaluated first and then the {@code exclude}. * exclusion has precedence, where the {@code include} is evaluated first and then the {@code exclude}.
*/ */
public class IncludeExclude implements Writeable, ToXContent { public class IncludeExclude implements Writeable, ToXContentFragment {
public static final ParseField INCLUDE_FIELD = new ParseField("include"); public static final ParseField INCLUDE_FIELD = new ParseField("include");
public static final ParseField EXCLUDE_FIELD = new ParseField("exclude"); public static final ParseField EXCLUDE_FIELD = new ParseField("exclude");
public static final ParseField PARTITION_FIELD = new ParseField("partition"); public static final ParseField PARTITION_FIELD = new ParseField("partition");

View File

@ -21,18 +21,17 @@ package org.elasticsearch.search.aggregations.bucket.terms;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionException; import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation; import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.InternalOrder; import org.elasticsearch.search.aggregations.InternalOrder;
import org.elasticsearch.search.aggregations.KeyComparable; import org.elasticsearch.search.aggregations.KeyComparable;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -43,7 +42,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
public abstract class InternalTerms<A extends InternalTerms<A, B>, B extends InternalTerms.Bucket<B>> public abstract class InternalTerms<A extends InternalTerms<A, B>, B extends InternalTerms.Bucket<B>>
extends InternalMultiBucketAggregation<A, B> implements Terms, ToXContent { extends InternalMultiBucketAggregation<A, B> implements Terms {
protected static final ParseField DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME = new ParseField("doc_count_error_upper_bound"); protected static final ParseField DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME = new ParseField("doc_count_error_upper_bound");
protected static final ParseField SUM_OF_OTHER_DOC_COUNTS = new ParseField("sum_other_doc_count"); protected static final ParseField SUM_OF_OTHER_DOC_COUNTS = new ParseField("sum_other_doc_count");

View File

@ -25,21 +25,21 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.util.Comparators; import org.elasticsearch.common.util.Comparators;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.InternalOrder;
import org.elasticsearch.search.aggregations.InternalOrder.Aggregation;
import org.elasticsearch.search.aggregations.InternalOrder.CompoundOrder;
import org.elasticsearch.search.aggregations.bucket.BucketsAggregator; import org.elasticsearch.search.aggregations.bucket.BucketsAggregator;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket; import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator; import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregator;
import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator; import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.support.AggregationPath; import org.elasticsearch.search.aggregations.support.AggregationPath;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.InternalOrder;
import org.elasticsearch.search.aggregations.InternalOrder.Aggregation;
import org.elasticsearch.search.aggregations.InternalOrder.CompoundOrder;
import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException; import java.io.IOException;
@ -52,7 +52,7 @@ import java.util.Set;
public abstract class TermsAggregator extends BucketsAggregator { public abstract class TermsAggregator extends BucketsAggregator {
public static class BucketCountThresholds implements Writeable, ToXContent { public static class BucketCountThresholds implements Writeable, ToXContentFragment {
private long minDocCount; private long minDocCount;
private long shardMinDocCount; private long shardMinDocCount;
private int requiredSize; private int requiredSize;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.search.aggregations.pipeline.movavg.models;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.NamedWriteable;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
@ -30,7 +30,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
public abstract class MovAvgModel implements NamedWriteable, ToXContent { public abstract class MovAvgModel implements NamedWriteable, ToXContentFragment {
/** /**
* Should this model be fit to the data via a cost minimizing algorithm by default? * Should this model be fit to the data via a cost minimizing algorithm by default?

View File

@ -1245,7 +1245,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
return builder; return builder;
} }
public static class IndexBoost implements Writeable, ToXContent { public static class IndexBoost implements Writeable, ToXContentObject {
private final String index; private final String index;
private final float boost; private final float boost;

View File

@ -26,7 +26,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.common.xcontent.support.XContentMapValues;
@ -42,7 +42,7 @@ import java.util.function.Function;
/** /**
* Context used to fetch the {@code _source}. * Context used to fetch the {@code _source}.
*/ */
public class FetchSourceContext implements Writeable, ToXContent { public class FetchSourceContext implements Writeable, ToXContentObject {
public static final ParseField INCLUDES_FIELD = new ParseField("includes", "include"); public static final ParseField INCLUDES_FIELD = new ParseField("includes", "include");
public static final ParseField EXCLUDES_FIELD = new ParseField("excludes", "exclude"); public static final ParseField EXCLUDES_FIELD = new ParseField("excludes", "exclude");

View File

@ -24,7 +24,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -39,7 +39,7 @@ import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpect
/** /**
* A field highlighted with its highlighted fragments. * A field highlighted with its highlighted fragments.
*/ */
public class HighlightField implements ToXContent, Streamable { public class HighlightField implements ToXContentFragment, Streamable {
private String name; private String name;

View File

@ -23,7 +23,7 @@ import org.elasticsearch.action.search.SearchResponseSections;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.profile.SearchProfileShardResults; import org.elasticsearch.search.profile.SearchProfileShardResults;
@ -34,7 +34,7 @@ import java.io.IOException;
/** /**
* {@link SearchResponseSections} subclass that can be serialized over the wire. * {@link SearchResponseSections} subclass that can be serialized over the wire.
*/ */
public class InternalSearchResponse extends SearchResponseSections implements Writeable, ToXContent { public class InternalSearchResponse extends SearchResponseSections implements Writeable, ToXContentFragment {
public static InternalSearchResponse empty() { public static InternalSearchResponse empty() {
return new InternalSearchResponse(SearchHits.empty(), null, null, null, false, null, 1); return new InternalSearchResponse(SearchHits.empty(), null, null, null, false, null, 1);

View File

@ -22,7 +22,7 @@ package org.elasticsearch.search.profile.aggregation;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.profile.ProfileResult; import org.elasticsearch.search.profile.ProfileResult;
@ -38,7 +38,7 @@ import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpect
* A container class to hold the profile results for a single shard in the request. * A container class to hold the profile results for a single shard in the request.
* Contains a list of query profiles, a collector tree and a total rewrite tree. * Contains a list of query profiles, a collector tree and a total rewrite tree.
*/ */
public final class AggregationProfileShardResult implements Writeable, ToXContent { public final class AggregationProfileShardResult implements Writeable, ToXContentFragment {
public static final String AGGREGATIONS = "aggregations"; public static final String AGGREGATIONS = "aggregations";
private final List<ProfileResult> aggProfileResults; private final List<ProfileResult> aggProfileResults;

View File

@ -24,12 +24,12 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
public class CompletionStats implements Streamable, ToXContent { public class CompletionStats implements Streamable, ToXContentFragment {
private static final String COMPLETION = "completion"; private static final String COMPLETION = "completion";
private static final String SIZE_IN_BYTES = "size_in_bytes"; private static final String SIZE_IN_BYTES = "size_in_bytes";

View File

@ -27,7 +27,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -37,7 +37,7 @@ import java.util.Objects;
/** /**
* Fuzzy options for completion suggester * Fuzzy options for completion suggester
*/ */
public class FuzzyOptions implements ToXContent, Writeable { public class FuzzyOptions implements ToXContentFragment, Writeable {
static final ParseField FUZZY_OPTIONS = new ParseField("fuzzy"); static final ParseField FUZZY_OPTIONS = new ParseField("fuzzy");
private static final ParseField TRANSPOSITION_FIELD = new ParseField("transpositions"); private static final ParseField TRANSPOSITION_FIELD = new ParseField("transpositions");
private static final ParseField MIN_LENGTH_FIELD = new ParseField("min_length"); private static final ParseField MIN_LENGTH_FIELD = new ParseField("min_length");

View File

@ -23,7 +23,7 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -37,7 +37,7 @@ import static org.elasticsearch.search.suggest.completion.context.CategoryContex
/** /**
* Defines the query context for {@link CategoryContextMapping} * Defines the query context for {@link CategoryContextMapping}
*/ */
public final class CategoryQueryContext implements ToXContent { public final class CategoryQueryContext implements ToXContentObject {
public static final String NAME = "category"; public static final String NAME = "category";
private final String category; private final String category;

View File

@ -21,6 +21,7 @@ package org.elasticsearch.search.suggest.completion.context;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.common.xcontent.XContentParser.Token;
@ -40,7 +41,7 @@ import java.util.Set;
* *
* Implementations have to define how contexts are parsed at query/index time * Implementations have to define how contexts are parsed at query/index time
*/ */
public abstract class ContextMapping<T extends ToXContent> implements ToXContent { public abstract class ContextMapping<T extends ToXContent> implements ToXContentFragment {
public static final String FIELD_TYPE = "type"; public static final String FIELD_TYPE = "type";
public static final String FIELD_NAME = "name"; public static final String FIELD_NAME = "name";

View File

@ -30,6 +30,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.mapper.CompletionFieldMapper; import org.elasticsearch.index.mapper.CompletionFieldMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser; import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.search.suggest.completion.context.ContextMapping.Type;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -43,7 +44,6 @@ import java.util.Set;
import static org.elasticsearch.search.suggest.completion.context.ContextMapping.FIELD_NAME; import static org.elasticsearch.search.suggest.completion.context.ContextMapping.FIELD_NAME;
import static org.elasticsearch.search.suggest.completion.context.ContextMapping.FIELD_TYPE; import static org.elasticsearch.search.suggest.completion.context.ContextMapping.FIELD_TYPE;
import static org.elasticsearch.search.suggest.completion.context.ContextMapping.Type;
/** /**
* ContextMappings indexes context-enabled suggestion fields * ContextMappings indexes context-enabled suggestion fields

View File

@ -24,7 +24,7 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.geo.GeoUtils; import org.elasticsearch.common.geo.GeoUtils;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -41,7 +41,7 @@ import static org.elasticsearch.search.suggest.completion.context.GeoContextMapp
/** /**
* Defines the query context for {@link GeoContextMapping} * Defines the query context for {@link GeoContextMapping}
*/ */
public final class GeoQueryContext implements ToXContent { public final class GeoQueryContext implements ToXContentObject {
public static final String NAME = "geo"; public static final String NAME = "geo";
private final GeoPoint geoPoint; private final GeoPoint geoPoint;

View File

@ -40,7 +40,7 @@ import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor; import org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler; import org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
@ -582,7 +582,7 @@ public class ThreadPool extends AbstractComponent implements Closeable {
} }
} }
public static class Info implements Writeable, ToXContent { public static class Info implements Writeable, ToXContentFragment {
private final String name; private final String name;
private final ThreadPoolType type; private final ThreadPoolType type;

View File

@ -315,7 +315,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
assertEquals(-8, parsed.mineral); assertEquals(-8, parsed.mineral);
} }
private static class HasCtorArguments implements ToXContent { private static class HasCtorArguments implements ToXContentObject {
@Nullable @Nullable
final String animal; final String animal;
@Nullable @Nullable

View File

@ -37,6 +37,7 @@ import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -368,7 +369,7 @@ public class MetaDataStateFormatTests extends ESTestCase {
} }
} }
private static class DummyState implements ToXContent { private static class DummyState implements ToXContentFragment {
String string; String string;
int aInt; int aInt;
long aLong; long aLong;

View File

@ -32,6 +32,7 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
@ -56,7 +57,7 @@ public class BlobStoreFormatIT extends AbstractSnapshotIntegTestCase {
public static final String BLOB_CODEC = "blob"; public static final String BLOB_CODEC = "blob";
private static class BlobObj implements ToXContent { private static class BlobObj implements ToXContentFragment {
private final String text; private final String text;

View File

@ -19,6 +19,7 @@
package org.elasticsearch.search.aggregations; package org.elasticsearch.search.aggregations;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
@ -124,6 +125,20 @@ public abstract class BaseAggregationTestCase<AB extends AbstractAggregationBuil
assertEquals(testAgg.hashCode(), newAgg.hashCode()); assertEquals(testAgg.hashCode(), newAgg.hashCode());
} }
/**
* Generic test that checks that the toString method renders the XContent
* correctly.
*/
public void testToString() throws IOException {
AB testAgg = createTestAggregatorBuilder();
String toString = randomBoolean() ? Strings.toString(testAgg) : testAgg.toString();
XContentParser parser = createParser(XContentType.JSON.xContent(), toString);
AggregationBuilder newAgg = parse(parser);
assertNotSame(newAgg, testAgg);
assertEquals(testAgg, newAgg);
assertEquals(testAgg.hashCode(), newAgg.hashCode());
}
protected AggregationBuilder parse(XContentParser parser) throws IOException { protected AggregationBuilder parse(XContentParser parser) throws IOException {
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
AggregatorFactories.Builder parsed = AggregatorFactories.parseAggregators(parser); AggregatorFactories.Builder parsed = AggregatorFactories.parseAggregators(parser);

View File

@ -20,6 +20,7 @@
package org.elasticsearch.test; package org.elasticsearch.test;
import com.fasterxml.jackson.core.io.JsonStringEncoder; import com.fasterxml.jackson.core.io.JsonStringEncoder;
import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermQuery;
@ -740,6 +741,21 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
} }
} }
/**
* Generic test that checks that the <code>Strings.toString()</code> method
* renders the XContent correctly.
*/
public void testValidOutput() throws IOException {
for (int runs = 0; runs < NUMBER_OF_TESTQUERIES; runs++) {
QB testQuery = createTestQueryBuilder();
XContentType xContentType = XContentType.JSON;
String toString = Strings.toString(testQuery);
assertParsedQuery(createParser(xContentType.xContent(), toString), testQuery);
BytesReference bytes = XContentHelper.toXContent(testQuery, xContentType, false);
assertParsedQuery(createParser(xContentType.xContent(), bytes), testQuery);
}
}
private QB changeNameOrBoost(QB original) throws IOException { private QB changeNameOrBoost(QB original) throws IOException {
QB secondQuery = copyQuery(original); QB secondQuery = copyQuery(original);
if (randomBoolean()) { if (randomBoolean()) {