diff options
Diffstat (limited to 'core/src/main/java/org/elasticsearch/rest/action/document')
-rw-r--r-- | core/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java | 20 | ||||
-rw-r--r-- | core/src/main/java/org/elasticsearch/rest/action/document/RestHeadAction.java | 23 |
2 files changed, 17 insertions, 26 deletions
diff --git a/core/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java b/core/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java index 83d424ed74..341c1ddc91 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java @@ -36,13 +36,19 @@ import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import java.io.IOException; import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.HEAD; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; +/** + * The REST handler for get source and head source APIs. + */ public class RestGetSourceAction extends BaseRestHandler { - public RestGetSourceAction(Settings settings, RestController controller) { + + public RestGetSourceAction(final Settings settings, final RestController controller) { super(settings); controller.registerHandler(GET, "/{index}/{type}/{id}/_source", this); + controller.registerHandler(HEAD, "/{index}/{type}/{id}/_source", this); } @Override @@ -50,7 +56,7 @@ public class RestGetSourceAction extends BaseRestHandler { final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id")); getRequest.operationThreaded(true); getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh())); - getRequest.routing(request.param("routing")); // order is important, set it after routing, so it will set the routing + getRequest.routing(request.param("routing")); getRequest.parent(request.param("parent")); getRequest.preference(request.param("preference")); getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime())); @@ -59,15 +65,16 @@ public class RestGetSourceAction extends BaseRestHandler { return channel -> { if (getRequest.fetchSourceContext() != null && !getRequest.fetchSourceContext().fetchSource()) { - ActionRequestValidationException validationError = new ActionRequestValidationException(); + final ActionRequestValidationException validationError = new ActionRequestValidationException(); validationError.addValidationError("fetching source can not be disabled"); channel.sendResponse(new BytesRestResponse(channel, validationError)); } else { client.get(getRequest, new RestResponseListener<GetResponse>(channel) { @Override - public RestResponse buildResponse(GetResponse response) throws Exception { - XContentBuilder builder = channel.newBuilder(request.getXContentType(), false); - if (response.isSourceEmpty()) { // check if doc source (or doc itself) is missing + public RestResponse buildResponse(final GetResponse response) throws Exception { + final XContentBuilder builder = channel.newBuilder(request.getXContentType(), false); + // check if doc source (or doc itself) is missing + if (response.isSourceEmpty()) { return new BytesRestResponse(NOT_FOUND, builder); } else { builder.rawValue(response.getSourceInternal()); @@ -78,4 +85,5 @@ public class RestGetSourceAction extends BaseRestHandler { } }; } + } diff --git a/core/src/main/java/org/elasticsearch/rest/action/document/RestHeadAction.java b/core/src/main/java/org/elasticsearch/rest/action/document/RestHeadAction.java index cc90b2cfa0..14e412aebe 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/document/RestHeadAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/document/RestHeadAction.java @@ -48,33 +48,18 @@ public abstract class RestHeadAction extends BaseRestHandler { */ public static class Document extends RestHeadAction { public Document(Settings settings, RestController controller) { - super(settings, false); + super(settings); controller.registerHandler(HEAD, "/{index}/{type}/{id}", this); } } /** - * Handler to check for document source existence (may be disabled in the mapping). - */ - public static class Source extends RestHeadAction { - public Source(Settings settings, RestController controller) { - super(settings, true); - controller.registerHandler(HEAD, "/{index}/{type}/{id}/_source", this); - } - } - - private final boolean source; - - /** * All subclasses must be registered in {@link org.elasticsearch.common.network.NetworkModule}. + * @param settings injected settings * - * @param settings injected settings - * @param source {@code false} to check for {@link GetResponse#isExists()}. - * {@code true} to also check for {@link GetResponse#isSourceEmpty()}. */ - public RestHeadAction(Settings settings, boolean source) { + public RestHeadAction(Settings settings) { super(settings); - this.source = source; } @Override @@ -95,8 +80,6 @@ public abstract class RestHeadAction extends BaseRestHandler { public RestResponse buildResponse(GetResponse response) { if (!response.isExists()) { return new BytesRestResponse(NOT_FOUND, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY); - } else if (source && response.isSourceEmpty()) { // doc exists, but source might not (disabled in the mapping) - return new BytesRestResponse(NOT_FOUND, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY); } else { return new BytesRestResponse(OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY); } |