diff --git a/rest-api-spec/test/search/10_source_filtering.yaml b/rest-api-spec/test/search/10_source_filtering.yaml index 40a67ba7e1f..1a2a79a80e4 100644 --- a/rest-api-spec/test/search/10_source_filtering.yaml +++ b/rest-api-spec/test/search/10_source_filtering.yaml @@ -89,4 +89,10 @@ query: { match_all: {} } - match: { hits.hits.0.fields: { include.field2 : [v2] }} - is_true: hits.hits.0._source + + + - do: + search: + fielddata_fields: ["count"] + - match: { hits.hits.0.fields.count: [1] } diff --git a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 0d06031a92e..550b0f63978 100644 --- a/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -195,6 +195,20 @@ public class RestSearchAction extends BaseRestHandler { } } } + String sFieldDataFields = request.param("fielddata_fields"); + if (sFieldDataFields != null) { + if (searchSourceBuilder == null) { + searchSourceBuilder = new SearchSourceBuilder(); + } + if (Strings.hasText(sFieldDataFields)) { + String[] sFields = Strings.splitStringByCommaToArray(sFieldDataFields); + if (sFields != null) { + for (String field : sFields) { + searchSourceBuilder.fieldDataField(field); + } + } + } + } FetchSourceContext fetchSourceContext = FetchSourceContext.parseFromRestRequest(request); if (fetchSourceContext != null) { if (searchSourceBuilder == null) {