diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java index f6263e6a40f..0f27e99d906 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java @@ -228,7 +228,7 @@ public class MultiGetRequest implements ActionRequest { return this; } - public void add(@Nullable String defaultIndex, @Nullable String defaultType, byte[] data, int from, int length) throws Exception { + public void add(@Nullable String defaultIndex, @Nullable String defaultType, @Nullable String[] defaultFields, byte[] data, int from, int length) throws Exception { XContentParser parser = XContentFactory.xContent(data, from, length).createParser(data, from, length); try { XContentParser.Token token; @@ -269,7 +269,13 @@ public class MultiGetRequest implements ActionRequest { } } } - add(new Item(index, type, id).routing(routing).fields(fields == null ? null : fields.toArray(new String[fields.size()]))); + String[] aFields; + if (fields != null) { + aFields = fields.toArray(new String[fields.size()]); + } else { + aFields = defaultFields; + } + add(new Item(index, type, id).routing(routing).fields(aFields)); } } else if ("ids".equals(currentFieldName)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestMultiGetAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestMultiGetAction.java index b6f1b7e33b2..8637a596258 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestMultiGetAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestMultiGetAction.java @@ -23,6 +23,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.get.MultiGetRequest; import org.elasticsearch.action.get.MultiGetResponse; 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; @@ -58,8 +59,14 @@ public class RestMultiGetAction extends BaseRestHandler { multiGetRequest.preference(request.param("preference")); multiGetRequest.realtime(request.paramAsBooleanOptional("realtime", null)); + String[] sFields = null; + String sField = request.param("fields"); + if (sField != null) { + sFields = Strings.splitStringByCommaToArray(sField); + } + try { - multiGetRequest.add(request.param("index"), request.param("type"), request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength()); + multiGetRequest.add(request.param("index"), request.param("type"), sFields, request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength()); } catch (Exception e) { try { XContentBuilder builder = restContentBuilder(request);