Make the get source REST API source fetching query parameters consistent with other API

The get source rest endpoint now uses _source_* parameters.
 Also it will now throw a validation error if you turn off source fetching.

Closes #3886
This commit is contained in:
Boaz Leskes 2013-10-11 12:25:21 +02:00
parent f4cf5a7d4a
commit 977cb4a729
1 changed files with 10 additions and 15 deletions

View File

@ -20,10 +20,10 @@
package org.elasticsearch.rest.action.get; package org.elasticsearch.rest.action.get;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -60,21 +60,16 @@ public class RestGetSourceAction extends BaseRestHandler {
getRequest.preference(request.param("preference")); getRequest.preference(request.param("preference"));
getRequest.realtime(request.paramAsBooleanOptional("realtime", null)); getRequest.realtime(request.paramAsBooleanOptional("realtime", null));
String[] includes = null, excludes = null; getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));
String sIncludes = request.param("include");
sIncludes = request.param("includes", sIncludes);
if (sIncludes != null) {
includes = Strings.splitStringByCommaToArray(sIncludes);
}
String sExcludes = request.param("exclude"); if (getRequest.fetchSourceContext() != null && !getRequest.fetchSourceContext().fetchSource()) {
sExcludes = request.param("excludes", sExcludes); try {
if (sExcludes != null) { ActionRequestValidationException validationError = new ActionRequestValidationException();
excludes = Strings.splitStringByCommaToArray(sExcludes); validationError.addValidationError("fetching source can not be disabled");
channel.sendResponse(new XContentThrowableRestResponse(request, validationError));
} catch (IOException e) {
logger.error("Failed to send failure response", e);
} }
if (includes != null || excludes != null) {
getRequest.fetchSourceContext(new FetchSourceContext(includes, excludes));
} }
client.get(getRequest, new ActionListener<GetResponse>() { client.get(getRequest, new ActionListener<GetResponse>() {