@@ -213,8 +213,6 @@ public static HighlightBuilder highlight() {
213213
214214 private boolean skipInnerHits = false ;
215215
216- private String projectRouting ;
217-
218216 /**
219217 * Constructs a new search source builder.
220218 */
@@ -612,19 +610,6 @@ public TimeValue timeout() {
612610 return timeout ;
613611 }
614612
615- public String projectRouting () {
616- return projectRouting ;
617- }
618-
619- public SearchSourceBuilder projectRouting (String projectRouting ) {
620- if (this .projectRouting != null ) {
621- throw new IllegalArgumentException ("project_routing is already set" );
622- }
623-
624- this .projectRouting = projectRouting ;
625- return this ;
626- }
627-
628613 /**
629614 * An optional terminate_after to terminate the search after collecting
630615 * <code>terminateAfter</code> documents
@@ -1342,6 +1327,26 @@ private SearchSourceBuilder shallowCopy(
13421327 return rewrittenBuilder ;
13431328 }
13441329
1330+ /**
1331+ * Parse some xContent into this SearchSourceBuilder, overwriting any values specified in the xContent.
1332+ *
1333+ * @param searchRequest The SearchRequest object that's representing the request we're parsing which shall receive
1334+ * the parsed info.
1335+ * @param parser The xContent parser.
1336+ * @param checkTrailingTokens If true throws a parsing exception when extra tokens are found after the main object.
1337+ * @param searchUsageHolder holder for the search usage statistics
1338+ * @param clusterSupportsFeature used to check if certain features are available on this cluster
1339+ */
1340+ public SearchSourceBuilder parseXContent (
1341+ SearchRequest searchRequest ,
1342+ XContentParser parser ,
1343+ boolean checkTrailingTokens ,
1344+ SearchUsageHolder searchUsageHolder ,
1345+ Predicate <NodeFeature > clusterSupportsFeature
1346+ ) throws IOException {
1347+ return parseXContent (searchRequest , parser , checkTrailingTokens , searchUsageHolder ::updateUsage , clusterSupportsFeature );
1348+ }
1349+
13451350 /**
13461351 * Parse some xContent into this SearchSourceBuilder, overwriting any values specified in the xContent.
13471352 *
@@ -1356,7 +1361,27 @@ public SearchSourceBuilder parseXContent(
13561361 SearchUsageHolder searchUsageHolder ,
13571362 Predicate <NodeFeature > clusterSupportsFeature
13581363 ) throws IOException {
1359- return parseXContent (parser , checkTrailingTokens , searchUsageHolder ::updateUsage , clusterSupportsFeature );
1364+ return parseXContent (null , parser , checkTrailingTokens , searchUsageHolder ::updateUsage , clusterSupportsFeature );
1365+ }
1366+
1367+ /**
1368+ * Parse some xContent into this SearchSourceBuilder, overwriting any values specified in the xContent.
1369+ * This variant does not record search features usage. Most times the variant that accepts a {@link SearchUsageHolder} and records
1370+ * usage stats into it is the one to use.
1371+ *
1372+ * @param searchRequest The SearchRequest object that's representing the request we're parsing which shall receive
1373+ * the parsed info.
1374+ * @param parser The xContent parser.
1375+ * @param checkTrailingTokens If true throws a parsing exception when extra tokens are found after the main object.
1376+ * @param clusterSupportsFeature used to check if certain features are available on this cluster
1377+ */
1378+ public SearchSourceBuilder parseXContent (
1379+ SearchRequest searchRequest ,
1380+ XContentParser parser ,
1381+ boolean checkTrailingTokens ,
1382+ Predicate <NodeFeature > clusterSupportsFeature
1383+ ) throws IOException {
1384+ return parseXContent (searchRequest , parser , checkTrailingTokens , s -> {}, clusterSupportsFeature );
13601385 }
13611386
13621387 /**
@@ -1373,10 +1398,11 @@ public SearchSourceBuilder parseXContent(
13731398 boolean checkTrailingTokens ,
13741399 Predicate <NodeFeature > clusterSupportsFeature
13751400 ) throws IOException {
1376- return parseXContent (parser , checkTrailingTokens , s -> {}, clusterSupportsFeature );
1401+ return parseXContent (null , parser , checkTrailingTokens , s -> {}, clusterSupportsFeature );
13771402 }
13781403
13791404 private SearchSourceBuilder parseXContent (
1405+ SearchRequest searchRequest ,
13801406 XContentParser parser ,
13811407 boolean checkTrailingTokens ,
13821408 Consumer <SearchUsage > searchUsageConsumer ,
@@ -1399,7 +1425,11 @@ private SearchSourceBuilder parseXContent(
13991425 currentFieldName = parser .currentName ();
14001426 } else if (token .isValue ()) {
14011427 if (PROJECT_ROUTING .match (currentFieldName , parser .getDeprecationHandler ())) {
1402- projectRouting (parser .text ());
1428+ /*
1429+ * If project_routing was specified as a query parameter too, setProjectRouting() will throw
1430+ * an error to prevent setting twice or overwriting previously set value.
1431+ */
1432+ searchRequest .setProjectRouting (parser .text ());
14031433 } else if (FROM_FIELD .match (currentFieldName , parser .getDeprecationHandler ())) {
14041434 from (parser .intValue ());
14051435 } else if (SIZE_FIELD .match (currentFieldName , parser .getDeprecationHandler ())) {
0 commit comments