diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchResponse.java index 70a339a0926..8755cb16fae 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchResponse.java @@ -27,6 +27,8 @@ import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.ToJson; +import org.elasticsearch.util.xcontent.ToXContent; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -38,7 +40,7 @@ import static org.elasticsearch.search.internal.InternalSearchResponse.*; * * @author kimchy (shay.banon) */ -public class SearchResponse implements ActionResponse, ToJson { +public class SearchResponse implements ActionResponse, ToXContent { private InternalSearchResponse internalResponse; @@ -161,7 +163,7 @@ public class SearchResponse implements ActionResponse, ToJson { return scrollId; } - @Override public void toJson(JsonBuilder builder, Params params) throws IOException { + @Override public void toXContent(XContentBuilder builder, Params params) throws IOException { if (scrollId != null) { builder.field("_scrollId", scrollId); } @@ -185,7 +187,7 @@ public class SearchResponse implements ActionResponse, ToJson { } builder.endObject(); - internalResponse.toJson(builder, params); + internalResponse.toXContent(builder, params); } public static SearchResponse readSearchResponse(StreamInput in) throws IOException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/JsonRestResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/JsonRestResponse.java index 7672079e5d5..2d920179d67 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/JsonRestResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/JsonRestResponse.java @@ -21,7 +21,7 @@ package org.elasticsearch.rest; import org.apache.lucene.util.UnicodeUtil; import org.elasticsearch.util.ThreadLocals; -import org.elasticsearch.util.json.JsonBuilder; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -49,16 +49,16 @@ public class JsonRestResponse extends AbstractRestResponse { private final Status status; - private final JsonBuilder jsonBuilder; + private final XContentBuilder builder; public JsonRestResponse(RestRequest request, Status status) { - this.jsonBuilder = null; + this.builder = null; this.status = status; this.prefixUtf8Result = startJsonp(request); } - public JsonRestResponse(RestRequest request, Status status, JsonBuilder jsonBuilder) throws IOException { - this.jsonBuilder = jsonBuilder; + public JsonRestResponse(RestRequest request, Status status, XContentBuilder builder) throws IOException { + this.builder = builder; this.status = status; this.prefixUtf8Result = startJsonp(request); } @@ -72,11 +72,11 @@ public class JsonRestResponse extends AbstractRestResponse { } @Override public byte[] content() throws IOException { - return jsonBuilder.unsafeBytes(); + return builder.unsafeBytes(); } @Override public int contentLength() throws IOException { - return jsonBuilder.unsafeBytesLength(); + return builder.unsafeBytesLength(); } @Override public Status status() { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/JsonThrowableRestResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/JsonThrowableRestResponse.java index e8b778f31f5..33152f8516f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/JsonThrowableRestResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/JsonThrowableRestResponse.java @@ -19,12 +19,12 @@ package org.elasticsearch.rest; -import org.elasticsearch.util.json.JsonBuilder; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import static org.elasticsearch.ExceptionsHelper.*; -import static org.elasticsearch.util.json.JsonBuilder.*; +import static org.elasticsearch.rest.action.support.RestXContentBuilder.*; /** * @author kimchy (Shay Banon) @@ -39,8 +39,8 @@ public class JsonThrowableRestResponse extends JsonRestResponse { super(request, status, convert(request, t)); } - private static JsonBuilder convert(RestRequest request, Throwable t) throws IOException { - JsonBuilder builder = binaryJsonBuilder().prettyPrint() + private static XContentBuilder convert(RestRequest request, Throwable t) throws IOException { + XContentBuilder builder = restContentBuilder(request) .startObject().field("error", detailedMessage(t)); if (t != null && request.paramAsBoolean("error_trace", false)) { builder.startObject("error_trace"); @@ -62,7 +62,7 @@ public class JsonThrowableRestResponse extends JsonRestResponse { return builder; } - private static void buildThrowable(Throwable t, JsonBuilder builder) throws IOException { + private static void buildThrowable(Throwable t, XContentBuilder builder) throws IOException { builder.field("message", t.getMessage()); for (StackTraceElement stElement : t.getStackTrace()) { builder.startObject("at") diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java index 565df204260..02df2482a70 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java @@ -21,7 +21,7 @@ package org.elasticsearch.rest; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.json.ToJson; +import org.elasticsearch.util.xcontent.ToXContent; import java.io.InputStream; import java.util.List; @@ -31,7 +31,7 @@ import java.util.Set; /** * @author kimchy (shay.banon) */ -public interface RestRequest extends ToJson.Params { +public interface RestRequest extends ToXContent.Params { enum Method { GET, POST, PUT, DELETE diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java index 063e2bbe8c3..be123dc3877 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java @@ -19,15 +19,16 @@ package org.elasticsearch.rest.action.admin.cluster.health; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.health.*; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -68,7 +69,7 @@ public class RestClusterHealthAction extends BaseRestHandler { } } catch (Exception e) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject())); } catch (IOException e1) { logger.error("Failed to send failure response", e1); @@ -79,7 +80,7 @@ public class RestClusterHealthAction extends BaseRestHandler { client.admin().cluster().health(clusterHealthRequest, new ActionListener() { @Override public void onResponse(ClusterHealthResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("status", response.status().name().toLowerCase()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java index 01eb2b9fb43..0de9fa121b2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.admin.cluster.node.info; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; @@ -27,9 +28,9 @@ import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Map; @@ -54,7 +55,7 @@ public class RestNodesInfoAction extends BaseRestHandler { client.admin().cluster().nodesInfo(nodesInfoRequest, new ActionListener() { @Override public void onResponse(NodesInfoResponse result) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("cluster_name", result.clusterName().value()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java index b5909bcd5c8..bf5be89bb66 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.admin.cluster.node.shutdown; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownRequest; @@ -26,12 +27,14 @@ import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownRespons import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; +import static org.elasticsearch.rest.action.support.RestXContentBuilder.restContentBuilder; + /** * @author kimchy (shay.banon) */ @@ -52,7 +55,7 @@ public class RestNodesShutdownAction extends BaseRestHandler { client.admin().cluster().nodesShutdown(nodesShutdownRequest, new ActionListener() { @Override public void onResponse(NodesShutdownResponse result) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = restContentBuilder(request); builder.startObject(); builder.field("cluster_name", result.clusterName().value()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/broadcast/RestBroadcastPingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/broadcast/RestBroadcastPingAction.java index da53903ddc7..1a5ed9eb45e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/broadcast/RestBroadcastPingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/broadcast/RestBroadcastPingAction.java @@ -27,9 +27,10 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -59,7 +60,7 @@ public class RestBroadcastPingAction extends BaseRestHandler { client.admin().cluster().ping(broadcastPingRequest, new ActionListener() { @Override public void onResponse(BroadcastPingResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("ok", true); buildBroadcastShardsHeader(builder, response); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/replication/RestReplicationPingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/replication/RestReplicationPingAction.java index b4805b12ab6..1261299eff8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/replication/RestReplicationPingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/replication/RestReplicationPingAction.java @@ -28,9 +28,10 @@ import org.elasticsearch.action.admin.cluster.ping.replication.ShardReplicationP import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -54,7 +55,7 @@ public class RestReplicationPingAction extends BaseRestHandler { client.admin().cluster().ping(replicationPingRequest, new ActionListener() { @Override public void onResponse(ReplicationPingResponse result) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("ok", true); for (IndexReplicationPingResponse indexResponse : result.indices().values()) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/single/RestSinglePingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/single/RestSinglePingAction.java index 096110a7d22..cda6103a2fc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/single/RestSinglePingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/single/RestSinglePingAction.java @@ -19,15 +19,16 @@ package org.elasticsearch.rest.action.admin.cluster.ping.single; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -53,7 +54,7 @@ public class RestSinglePingAction extends BaseRestHandler { client.admin().cluster().ping(singlePingRequest, new ActionListener() { @Override public void onResponse(SinglePingResponse result) { try { - JsonBuilder generator = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder generator = RestXContentBuilder.restContentBuilder(request); generator.startObject().field("ok", true).endObject(); channel.sendResponse(new JsonRestResponse(request, OK, generator)); } catch (Exception e) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java index abac37370f4..28e8becc429 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java @@ -19,7 +19,6 @@ package org.elasticsearch.rest.action.admin.cluster.state; -import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; @@ -31,9 +30,10 @@ import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; -import org.elasticsearch.util.json.JsonBuilder; +import org.elasticsearch.rest.action.support.RestXContentBuilder; +import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Map; @@ -54,7 +54,7 @@ public class RestClusterStateAction extends BaseRestHandler { @Override public void onResponse(ClusterStateResponse response) { try { ClusterState state = response.state(); - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); // meta data @@ -125,7 +125,7 @@ public class RestClusterStateAction extends BaseRestHandler { } } - private void jsonShardRouting(JsonBuilder builder, ShardRouting shardRouting) throws IOException { + private void jsonShardRouting(XContentBuilder builder, ShardRouting shardRouting) throws IOException { builder.startObject() .field("state", shardRouting.state()) .field("primary", shardRouting.primary()) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java index 5a91b12a7f7..08fd76f43db 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java @@ -19,7 +19,6 @@ package org.elasticsearch.rest.action.admin.indices.alias; -import org.elasticsearch.util.guice.inject.Inject; import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonToken; import org.elasticsearch.ElasticSearchIllegalArgumentException; @@ -29,15 +28,16 @@ import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; +import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.json.Jackson; -import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import static org.elasticsearch.rest.RestRequest.Method.*; import static org.elasticsearch.rest.RestResponse.Status.*; +import static org.elasticsearch.rest.action.support.RestXContentBuilder.*; /** * @author kimchy (shay.banon) @@ -116,7 +116,7 @@ public class RestIndicesAliasesAction extends BaseRestHandler { client.admin().indices().aliases(indicesAliasesRequest, new ActionListener() { @Override public void onResponse(IndicesAliasesResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = restContentBuilder(request); builder.startObject() .field("ok", true) .endObject(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java index da72b8233f0..c6441cc147e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.admin.indices.cache.clear; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; @@ -27,9 +28,8 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; -import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -66,7 +66,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler { clearIndicesCacheRequest.operationThreading(operationThreading); } catch (Exception e) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); } catch (IOException e1) { logger.error("Failed to send failure response", e1); @@ -76,7 +76,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler { client.admin().indices().clearCache(clearIndicesCacheRequest, new ActionListener() { @Override public void onResponse(ClearIndicesCacheResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("ok", true); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java index 0cbf26f864c..b22b6bc1a23 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java @@ -19,7 +19,6 @@ package org.elasticsearch.rest.action.admin.indices.create; -import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; @@ -27,12 +26,13 @@ import org.elasticsearch.client.Client; import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.indices.InvalidIndexNameException; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.Strings; -import org.elasticsearch.util.json.JsonBuilder; +import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.settings.ImmutableSettings; import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.SettingsException; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -71,7 +71,7 @@ public class RestCreateIndexAction extends BaseRestHandler { client.admin().indices().create(createIndexRequest, new ActionListener() { @Override public void onResponse(CreateIndexResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject() .field("ok", true) .field("acknowledged", response.acknowledged()) @@ -86,7 +86,7 @@ public class RestCreateIndexAction extends BaseRestHandler { try { Throwable t = unwrapCause(e); if (t instanceof IndexAlreadyExistsException || t instanceof InvalidIndexNameException) { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", t.getMessage()).endObject())); } else { channel.sendResponse(new JsonThrowableRestResponse(request, e)); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java index b6f4ba85743..c7b9f4ae42b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.admin.indices.delete; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; @@ -26,9 +27,9 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.client.Client; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -52,7 +53,7 @@ public class RestDeleteIndexAction extends BaseRestHandler { client.admin().indices().delete(deleteIndexRequest, new ActionListener() { @Override public void onResponse(DeleteIndexResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject() .field("ok", true) .field("acknowledged", response.acknowledged()) @@ -67,7 +68,7 @@ public class RestDeleteIndexAction extends BaseRestHandler { try { Throwable t = unwrapCause(e); if (t instanceof IndexMissingException) { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", t.getMessage()).endObject())); } else { channel.sendResponse(new JsonThrowableRestResponse(request, e)); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java index 651033ca2d4..50ecad79343 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.admin.indices.flush; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.flush.FlushRequest; @@ -27,9 +28,9 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -65,7 +66,7 @@ public class RestFlushAction extends BaseRestHandler { client.admin().indices().flush(flushRequest, new ActionListener() { @Override public void onResponse(FlushResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("ok", true); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java index 99dd59bd324..dc623941fed 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java @@ -27,9 +27,10 @@ import org.elasticsearch.action.admin.indices.gateway.snapshot.IndexGatewaySnaps import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -55,7 +56,7 @@ public class RestGatewaySnapshotAction extends BaseRestHandler { client.admin().indices().gatewaySnapshot(gatewaySnapshotRequest, new ActionListener() { @Override public void onResponse(GatewaySnapshotResponse result) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("ok", true); builder.startObject("indices"); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java index 938fe9b914a..ec01b636dff 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java @@ -28,9 +28,10 @@ import org.elasticsearch.index.mapper.InvalidTypeNameException; import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -64,7 +65,7 @@ public class RestPutMappingAction extends BaseRestHandler { client.admin().indices().putMapping(putMappingRequest, new ActionListener() { @Override public void onResponse(PutMappingResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject() .field("ok", true) .field("acknowledged", response.acknowledged()); @@ -77,7 +78,7 @@ public class RestPutMappingAction extends BaseRestHandler { @Override public void onFailure(Throwable e) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); Throwable t = unwrapCause(e); if (t instanceof IndexMissingException || t instanceof InvalidTypeNameException || t instanceof MergeMappingException) { channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", t.getMessage()).endObject())); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java index 6a16aa5e683..fea78d1fe03 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.admin.indices.optimize; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; @@ -27,9 +28,8 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; -import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -70,7 +70,7 @@ public class RestOptimizeAction extends BaseRestHandler { optimizeRequest.operationThreading(operationThreading); } catch (Exception e) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); } catch (IOException e1) { logger.error("Failed to send failure response", e1); @@ -80,7 +80,7 @@ public class RestOptimizeAction extends BaseRestHandler { client.admin().indices().optimize(optimizeRequest, new ActionListener() { @Override public void onResponse(OptimizeResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("ok", true); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java index 8114eaf9098..03ad4b211d3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java @@ -27,9 +27,10 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -64,7 +65,7 @@ public class RestRefreshAction extends BaseRestHandler { client.admin().indices().refresh(refreshRequest, new ActionListener() { @Override public void onResponse(RefreshResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("ok", true); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java index 2d3348af55c..1e035878f5d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java @@ -19,15 +19,16 @@ package org.elasticsearch.rest.action.admin.indices.status; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.status.*; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Map; @@ -60,7 +61,7 @@ public class RestIndicesStatusAction extends BaseRestHandler { client.admin().indices().status(indicesStatusRequest, new ActionListener() { @Override public void onResponse(IndicesStatusResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("ok", true); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java index 7fdc2bbd3db..de999ddff88 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java @@ -19,7 +19,6 @@ package org.elasticsearch.rest.action.count; -import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.count.CountRequest; import org.elasticsearch.action.count.CountResponse; @@ -27,9 +26,10 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; -import org.elasticsearch.util.json.JsonBuilder; +import org.elasticsearch.rest.action.support.RestXContentBuilder; +import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -74,7 +74,7 @@ public class RestCountAction extends BaseRestHandler { } } catch (Exception e) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); } catch (IOException e1) { logger.error("Failed to send failure response", e1); @@ -85,7 +85,7 @@ public class RestCountAction extends BaseRestHandler { client.count(countRequest, new ActionListener() { @Override public void onResponse(CountResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("count", response.count()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java index d0be783be5c..35b9377fe6f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java @@ -19,15 +19,16 @@ package org.elasticsearch.rest.action.delete; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -54,7 +55,7 @@ public class RestDeleteAction extends BaseRestHandler { client.delete(deleteRequest, new ActionListener() { @Override public void onResponse(DeleteResponse result) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject() .field("ok", true) .field("_index", result.index()) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java index 955a7523149..3e5ad586b94 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.deletebyquery; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.deletebyquery.DeleteByQueryRequest; @@ -28,9 +29,9 @@ import org.elasticsearch.action.deletebyquery.ShardDeleteByQueryRequest; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -63,7 +64,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler { deleteByQueryRequest.timeout(request.paramAsTime("timeout", ShardDeleteByQueryRequest.DEFAULT_TIMEOUT)); } catch (Exception e) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject())); } catch (IOException e1) { logger.error("Failed to send failure response", e1); @@ -73,7 +74,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler { client.deleteByQuery(deleteByQueryRequest, new ActionListener() { @Override public void onResponse(DeleteByQueryResponse result) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject().field("ok", true); builder.startObject("_indices"); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java index 675f182d325..ce9ee31d89d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java @@ -28,13 +28,14 @@ import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.regex.Pattern; import static org.elasticsearch.rest.RestRequest.Method.*; import static org.elasticsearch.rest.RestResponse.Status.*; -import static org.elasticsearch.rest.action.support.RestJsonBuilder.*; +import static org.elasticsearch.rest.action.support.RestXContentBuilder.*; /** * @author kimchy (Shay Banon) @@ -73,7 +74,7 @@ public class RestGetAction extends BaseRestHandler { @Override public void onResponse(GetResponse response) { try { if (!response.exists()) { - JsonBuilder builder = restJsonBuilder(request); + XContentBuilder builder = restContentBuilder(request); builder.startObject(); builder.field("_index", response.index()); builder.field("_type", response.type()); @@ -81,14 +82,13 @@ public class RestGetAction extends BaseRestHandler { builder.endObject(); channel.sendResponse(new JsonRestResponse(request, NOT_FOUND, builder)); } else { - JsonBuilder builder = restJsonBuilder(request); + XContentBuilder builder = restContentBuilder(request); builder.startObject(); builder.field("_index", response.index()); builder.field("_type", response.type()); builder.field("_id", response.id()); if (response.source() != null) { - builder.raw(", \"_source\" : "); - builder.raw(response.source()); + builder.rawField("_source", response.source()); } if (response.fields() != null && !response.fields().isEmpty()) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java index 1a0099d5846..6007cba4b36 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java @@ -19,15 +19,16 @@ package org.elasticsearch.rest.action.index; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -66,7 +67,7 @@ public class RestIndexAction extends BaseRestHandler { indexRequest.opType(IndexRequest.OpType.CREATE); } else { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", "opType [" + sOpType + "] not allowed, either [index] or [create] are allowed").endObject())); } catch (IOException e1) { logger.warn("Failed to send response", e1); @@ -81,7 +82,7 @@ public class RestIndexAction extends BaseRestHandler { client.index(indexRequest, new ActionListener() { @Override public void onResponse(IndexResponse result) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject() .field("ok", true) .field("_index", result.index()) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java index f5fe4593e64..7f3b3a33725 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java @@ -19,19 +19,19 @@ package org.elasticsearch.rest.action.main; -import org.elasticsearch.util.gcommon.collect.Iterators; -import org.elasticsearch.util.guice.inject.Inject; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.node.ArrayNode; import org.elasticsearch.Version; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.Classes; import org.elasticsearch.util.concurrent.jsr166y.ThreadLocalRandom; +import org.elasticsearch.util.gcommon.collect.Iterators; +import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.json.Jackson; -import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -66,7 +66,7 @@ public class RestMainAction extends BaseRestHandler { @Override public void handleRequest(RestRequest request, RestChannel channel) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request).prettyPrint(); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request).prettyPrint(); builder.startObject(); builder.field("ok", true); if (settings.get("name") != null) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java index 12ded4aaa45..770770ca71c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java @@ -30,13 +30,14 @@ import org.elasticsearch.search.Scroll; import org.elasticsearch.util.Unicode; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import static org.elasticsearch.client.Requests.*; import static org.elasticsearch.rest.RestRequest.Method.*; import static org.elasticsearch.rest.RestResponse.Status.*; -import static org.elasticsearch.rest.action.support.RestJsonBuilder.*; +import static org.elasticsearch.rest.action.support.RestXContentBuilder.*; import static org.elasticsearch.util.TimeValue.*; /** @@ -82,7 +83,7 @@ public class RestMoreLikeThisAction extends BaseRestHandler { } } catch (Exception e) { try { - JsonBuilder builder = restJsonBuilder(request); + XContentBuilder builder = restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); } catch (IOException e1) { logger.error("Failed to send failure response", e1); @@ -93,9 +94,9 @@ public class RestMoreLikeThisAction extends BaseRestHandler { client.moreLikeThis(mltRequest, new ActionListener() { @Override public void onResponse(SearchResponse response) { try { - JsonBuilder builder = restJsonBuilder(request); + XContentBuilder builder = restContentBuilder(request); builder.startObject(); - response.toJson(builder, request); + response.toXContent(builder, request); builder.endObject(); channel.sendResponse(new JsonRestResponse(request, OK, builder)); } catch (Exception e) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index b43f0655a69..b2e40e7f094 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -19,29 +19,29 @@ package org.elasticsearch.rest.action.search; -import org.elasticsearch.index.query.xcontent.QueryBuilders; -import org.elasticsearch.index.query.xcontent.QueryStringQueryBuilder; -import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.search.SearchOperationThreading; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.index.query.xcontent.QueryBuilders; +import org.elasticsearch.index.query.xcontent.QueryStringQueryBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.json.JsonBuilder; +import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.regex.Pattern; import static org.elasticsearch.rest.RestRequest.Method.*; import static org.elasticsearch.rest.RestResponse.Status.*; -import static org.elasticsearch.rest.action.support.RestJsonBuilder.*; +import static org.elasticsearch.rest.action.support.RestXContentBuilder.*; import static org.elasticsearch.util.TimeValue.*; /** @@ -81,7 +81,7 @@ public class RestSearchAction extends BaseRestHandler { searchRequest.operationThreading(operationThreading); } catch (Exception e) { try { - JsonBuilder builder = restJsonBuilder(request); + XContentBuilder builder = restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); } catch (IOException e1) { logger.error("Failed to send failure response", e1); @@ -91,9 +91,9 @@ public class RestSearchAction extends BaseRestHandler { client.search(searchRequest, new ActionListener() { @Override public void onResponse(SearchResponse response) { try { - JsonBuilder builder = restJsonBuilder(request); + XContentBuilder builder = restContentBuilder(request); builder.startObject(); - response.toJson(builder, request); + response.toXContent(builder, request); builder.endObject(); channel.sendResponse(new JsonRestResponse(request, OK, builder)); } catch (Exception e) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java index 796b4f6959d..6785464a5ab 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java @@ -29,12 +29,13 @@ import org.elasticsearch.rest.*; import org.elasticsearch.search.Scroll; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import static org.elasticsearch.rest.RestRequest.Method.*; import static org.elasticsearch.rest.RestResponse.Status.*; -import static org.elasticsearch.rest.action.support.RestJsonBuilder.*; +import static org.elasticsearch.rest.action.support.RestXContentBuilder.*; import static org.elasticsearch.util.TimeValue.*; /** @@ -67,7 +68,7 @@ public class RestSearchScrollAction extends BaseRestHandler { searchScrollRequest.operationThreading(operationThreading); } catch (Exception e) { try { - JsonBuilder builder = restJsonBuilder(request); + XContentBuilder builder = restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); } catch (IOException e1) { logger.error("Failed to send failure response", e1); @@ -78,9 +79,9 @@ public class RestSearchScrollAction extends BaseRestHandler { client.searchScroll(searchScrollRequest, new ActionListener() { @Override public void onResponse(SearchResponse response) { try { - JsonBuilder builder = restJsonBuilder(request); + XContentBuilder builder = restContentBuilder(request); builder.startObject(); - response.toJson(builder, request); + response.toXContent(builder, request); builder.endObject(); channel.sendResponse(new JsonRestResponse(request, OK, builder)); } catch (Exception e) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java index 5a739780580..2b973199b82 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java @@ -27,7 +27,7 @@ import org.elasticsearch.index.query.xcontent.QueryStringQueryBuilder; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.util.Strings; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.json.JsonBuilder; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.regex.Pattern; @@ -41,7 +41,7 @@ public class RestActions { public final static Pattern typesPattern = Pattern.compile(","); public final static Pattern nodesIdsPattern = Pattern.compile(","); - public static void buildBroadcastShardsHeader(JsonBuilder builder, BroadcastOperationResponse response) throws IOException { + public static void buildBroadcastShardsHeader(XContentBuilder builder, BroadcastOperationResponse response) throws IOException { builder.startObject("_shards"); builder.field("total", response.totalShards()); builder.field("successful", response.successfulShards()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestJsonBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java similarity index 70% rename from modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestJsonBuilder.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java index 9adad9d6bd6..289bc995e13 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestJsonBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java @@ -20,19 +20,19 @@ package org.elasticsearch.rest.action.support; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.util.json.BinaryJsonBuilder; +import org.elasticsearch.util.xcontent.XContentFactory; +import org.elasticsearch.util.xcontent.XContentType; +import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; import java.io.IOException; -import static org.elasticsearch.util.json.JsonBuilder.*; - /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ -public class RestJsonBuilder { +public class RestXContentBuilder { - public static BinaryJsonBuilder restJsonBuilder(RestRequest request) throws IOException { - BinaryJsonBuilder builder = binaryJsonBuilder(); + public static BinaryXContentBuilder restContentBuilder(RestRequest request) throws IOException { + BinaryXContentBuilder builder = XContentFactory.contentBinaryBuilder(XContentType.JSON); if (request.paramAsBoolean("pretty", false)) { builder.prettyPrint(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/terms/RestTermsAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/terms/RestTermsAction.java index ad19a2305bb..f9b477cac1f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/terms/RestTermsAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/terms/RestTermsAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.terms; +import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; @@ -28,9 +29,9 @@ import org.elasticsearch.action.terms.TermsRequest; import org.elasticsearch.action.terms.TermsResponse; import org.elasticsearch.client.Client; import org.elasticsearch.rest.*; -import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.regex.Pattern; @@ -108,7 +109,7 @@ public class RestTermsAction extends BaseRestHandler { termsRequest.sortType(request.param("sort")); } catch (Exception e) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); } catch (IOException e1) { logger.error("Failed to send failure response", e1); @@ -120,7 +121,7 @@ public class RestTermsAction extends BaseRestHandler { client.terms(termsRequest, new ActionListener() { @Override public void onResponse(TermsResponse response) { try { - JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); buildBroadcastShardsHeader(builder, response); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHit.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHit.java index 536e0346472..1b60033a2be 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHit.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHit.java @@ -24,6 +24,7 @@ import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.search.highlight.HighlightField; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.json.ToJson; +import org.elasticsearch.util.xcontent.ToXContent; import java.util.Map; @@ -33,7 +34,7 @@ import java.util.Map; * @author kimchy (shay.banon) * @see SearchHits */ -public interface SearchHit extends Streamable, ToJson, Iterable { +public interface SearchHit extends Streamable, ToXContent, Iterable { /** * The index of the hit. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHits.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHits.java index 7304dcb2771..46be9d9822b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHits.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHits.java @@ -21,13 +21,14 @@ package org.elasticsearch.search; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.json.ToJson; +import org.elasticsearch.util.xcontent.ToXContent; /** * The hits of a search request. * * @author kimchy (shay.banon) */ -public interface SearchHits extends Streamable, ToJson, Iterable { +public interface SearchHits extends Streamable, ToXContent, Iterable { /** * The total number of hits that matches the search request. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/CountFacet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/CountFacet.java index 5c83922cdf9..6f96b035af9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/CountFacet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/CountFacet.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.facets; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.json.JsonBuilder; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -82,7 +82,7 @@ public class CountFacet implements Facet { count += increment; } - @Override public void toJson(JsonBuilder builder, Params params) throws IOException { + @Override public void toXContent(XContentBuilder builder, Params params) throws IOException { builder.field(name, count); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/Facet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/Facet.java index 34aa813c1a1..608cd77e457 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/Facet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/Facet.java @@ -22,13 +22,14 @@ package org.elasticsearch.search.facets; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.json.ToJson; +import org.elasticsearch.util.xcontent.ToXContent; /** * A search facet. * * @author kimchy (shay.banon) */ -public interface Facet extends Streamable, ToJson { +public interface Facet extends Streamable, ToXContent { enum Type { /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/Facets.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/Facets.java index 5b1b3cfb036..5ac40def3c7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/Facets.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/Facets.java @@ -23,24 +23,24 @@ import org.elasticsearch.util.gcommon.collect.ImmutableList; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.json.JsonBuilder; -import org.elasticsearch.util.json.ToJson; +import org.elasticsearch.util.xcontent.ToXContent; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Map; +import static org.elasticsearch.search.facets.CountFacet.*; import static org.elasticsearch.util.gcommon.collect.Lists.*; import static org.elasticsearch.util.gcommon.collect.Maps.*; -import static org.elasticsearch.search.facets.CountFacet.*; /** * Facets of search action. * * @author kimchy (shay.banon) */ -public class Facets implements Streamable, ToJson, Iterable { +public class Facets implements Streamable, ToXContent, Iterable { private final List EMPTY = ImmutableList.of(); @@ -109,10 +109,10 @@ public class Facets implements Streamable, ToJson, Iterable { return facetsAsMap().get(name); } - @Override public void toJson(JsonBuilder builder, Params params) throws IOException { + @Override public void toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("facets"); for (Facet facet : facets) { - facet.toJson(builder, params); + facet.toXContent(builder, params); } builder.endObject(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java index 75925cf6cfd..f2d20729371 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java @@ -19,7 +19,6 @@ package org.elasticsearch.search.internal; -import org.elasticsearch.util.gcommon.collect.ImmutableMap; import org.apache.lucene.search.Explanation; import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.search.SearchHit; @@ -27,10 +26,12 @@ import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.highlight.HighlightField; import org.elasticsearch.util.Unicode; +import org.elasticsearch.util.gcommon.collect.ImmutableMap; import org.elasticsearch.util.gnu.trove.TIntObjectHashMap; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.json.JsonBuilder; +import org.elasticsearch.util.xcontent.XContentFactory; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import javax.annotation.Nullable; import java.io.IOException; @@ -189,7 +190,7 @@ public class InternalSearchHit implements SearchHit { this.shard = target; } - @Override public void toJson(JsonBuilder builder, Params params) throws IOException { + @Override public void toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field("_index", shard.index()); // builder.field("_shard", shard.shardId()); @@ -197,8 +198,12 @@ public class InternalSearchHit implements SearchHit { builder.field("_type", type()); builder.field("_id", id()); if (source() != null) { - builder.raw(", \"_source\" : "); - builder.raw(source()); + if (XContentFactory.xContentType(source()) == builder.contentType()) { + builder.field("_source"); + builder.value(source()); + } else { + builder.rawField("_source", source()); + } } if (fields != null && !fields.isEmpty()) { builder.startObject("fields"); @@ -242,7 +247,7 @@ public class InternalSearchHit implements SearchHit { builder.endObject(); } - private void buildExplanation(JsonBuilder builder, Explanation explanation) throws IOException { + private void buildExplanation(XContentBuilder builder, Explanation explanation) throws IOException { builder.startObject(); builder.field("value", explanation.getValue()); builder.field("description", explanation.getDescription()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java index 8597defd312..027b31cf99c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java @@ -27,6 +27,7 @@ import org.elasticsearch.util.gnu.trove.TIntObjectHashMap; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.json.JsonBuilder; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.IdentityHashMap; @@ -84,13 +85,13 @@ public class InternalSearchHits implements SearchHits { return this.hits; } - @Override public void toJson(JsonBuilder builder, Params params) throws IOException { + @Override public void toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("hits"); builder.field("total", totalHits); builder.field("hits"); builder.startArray(); for (SearchHit hit : hits) { - hit.toJson(builder, params); + hit.toXContent(builder, params); } builder.endArray(); builder.endObject(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java index 4109f23bb66..abbe92e410f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java @@ -26,6 +26,8 @@ import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.ToJson; +import org.elasticsearch.util.xcontent.ToXContent; +import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; @@ -35,7 +37,7 @@ import static org.elasticsearch.search.internal.InternalSearchHits.*; /** * @author kimchy (Shay Banon) */ -public class InternalSearchResponse implements Streamable, ToJson { +public class InternalSearchResponse implements Streamable, ToXContent { private InternalSearchHits hits; @@ -57,10 +59,10 @@ public class InternalSearchResponse implements Streamable, ToJson { return facets; } - @Override public void toJson(JsonBuilder builder, Params params) throws IOException { - hits.toJson(builder, params); + @Override public void toXContent(XContentBuilder builder, Params params) throws IOException { + hits.toXContent(builder, params); if (facets != null) { - facets.toJson(builder, params); + facets.toXContent(builder, params); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentGenerator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentGenerator.java index 76f5f619ed4..ca3be3e5df6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentGenerator.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentGenerator.java @@ -89,6 +89,8 @@ public interface XContentGenerator { void writeObjectFieldStart(String fieldName) throws IOException; + void writeRawFieldStart(String fieldName) throws IOException; + void flush() throws IOException; void close() throws IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/XContentBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/XContentBuilder.java index 3c7e5a75d77..2e2f7feffd1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/XContentBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/XContentBuilder.java @@ -280,7 +280,12 @@ public abstract class XContentBuilder { return builder; } - public abstract T raw(byte[] json) throws IOException; + public T rawField(String fieldName, byte[] content) throws IOException { + generator.writeRawFieldStart(fieldName); + return raw(content); + } + + public abstract T raw(byte[] content) throws IOException; public T value(Boolean value) throws IOException { return value(value.booleanValue()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContentGenerator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContentGenerator.java index 47160154f07..9c2e653f13d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContentGenerator.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContentGenerator.java @@ -158,6 +158,11 @@ public class JsonXContentGenerator implements XContentGenerator { generator.writeObjectFieldStart(fieldName); } + @Override public void writeRawFieldStart(String fieldName) throws IOException { + generator.writeRaw(", \"" + fieldName + "\" : "); + + } + @Override public void flush() throws IOException { generator.flush(); }