@@ -56,15 +56,15 @@ public record WeightedRetrieverSource(CompoundRetrieverBuilder.RetrieverSource r
5656 */
5757 public static ActionRequestValidationException validateParams (
5858 List <CompoundRetrieverBuilder .RetrieverSource > innerRetrievers ,
59- List <String > fields ,
59+ @ Nullable List <String > fields ,
6060 @ Nullable String query ,
6161 String retrieverName ,
6262 String retrieversParamName ,
6363 String fieldsParamName ,
6464 String queryParamName ,
6565 ActionRequestValidationException validationException
6666 ) {
67- if (fields . isEmpty () == false || query != null ) {
67+ if (fields != null || query != null ) {
6868 // Using the multi-fields query format
6969 if (query == null ) {
7070 // Return early here because the following validation checks assume a query param value is provided
@@ -87,6 +87,13 @@ public static ActionRequestValidationException validateParams(
8787 );
8888 }
8989
90+ if (fields != null && fields .isEmpty ()) {
91+ validationException = addValidationError (
92+ String .format (Locale .ROOT , "[%s] [%s] cannot be empty" , retrieverName , fieldsParamName ),
93+ validationException
94+ );
95+ }
96+
9097 if (innerRetrievers .isEmpty () == false ) {
9198 validationException = addValidationError (
9299 String .format (Locale .ROOT , "[%s] cannot combine [%s] and [%s]" , retrieverName , retrieversParamName , queryParamName ),
@@ -131,13 +138,15 @@ public static ActionRequestValidationException validateParams(
131138 * @return The inner retriever tree as a {@code RetrieverBuilder} list
132139 */
133140 public static List <RetrieverBuilder > generateInnerRetrievers (
134- List <String > fieldsAndWeights ,
141+ @ Nullable List <String > fieldsAndWeights ,
135142 String query ,
136143 Collection <IndexMetadata > indicesMetadata ,
137144 Function <List <WeightedRetrieverSource >, CompoundRetrieverBuilder <?>> innerNormalizerGenerator ,
138145 @ Nullable Consumer <Float > weightValidator
139146 ) {
140- Map <String , Float > parsedFieldsAndWeights = QueryParserHelper .parseFieldsAndWeights (fieldsAndWeights );
147+ Map <String , Float > parsedFieldsAndWeights = fieldsAndWeights != null
148+ ? QueryParserHelper .parseFieldsAndWeights (fieldsAndWeights )
149+ : Map .of ();
141150 if (weightValidator != null ) {
142151 parsedFieldsAndWeights .values ().forEach (weightValidator );
143152 }
0 commit comments