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:
parent
f4cf5a7d4a
commit
977cb4a729
|
@ -20,10 +20,10 @@
|
|||
package org.elasticsearch.rest.action.get;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.get.GetRequest;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -60,21 +60,16 @@ public class RestGetSourceAction extends BaseRestHandler {
|
|||
getRequest.preference(request.param("preference"));
|
||||
getRequest.realtime(request.paramAsBooleanOptional("realtime", null));
|
||||
|
||||
String[] includes = null, excludes = null;
|
||||
String sIncludes = request.param("include");
|
||||
sIncludes = request.param("includes", sIncludes);
|
||||
if (sIncludes != null) {
|
||||
includes = Strings.splitStringByCommaToArray(sIncludes);
|
||||
}
|
||||
getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));
|
||||
|
||||
String sExcludes = request.param("exclude");
|
||||
sExcludes = request.param("excludes", sExcludes);
|
||||
if (sExcludes != null) {
|
||||
excludes = Strings.splitStringByCommaToArray(sExcludes);
|
||||
if (getRequest.fetchSourceContext() != null && !getRequest.fetchSourceContext().fetchSource()) {
|
||||
try {
|
||||
ActionRequestValidationException validationError = new ActionRequestValidationException();
|
||||
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>() {
|
||||
|
|
Loading…
Reference in New Issue