@@ -279,7 +279,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
279
279
280
280
public static final Setting <String > CLUSTER_CONCURRENT_SEGMENT_SEARCH_MODE = Setting .simpleString (
281
281
"search.concurrent_segment_search.mode" ,
282
- CONCURRENT_SEGMENT_SEARCH_MODE_NONE ,
282
+ CONCURRENT_SEGMENT_SEARCH_MODE_AUTO ,
283
283
value -> {
284
284
switch (value ) {
285
285
case CONCURRENT_SEGMENT_SEARCH_MODE_ALL :
@@ -303,12 +303,11 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
303
303
// value == 0 means lucene slice computation will be used
304
304
public static final Setting <Integer > CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_SETTING = Setting .intSetting (
305
305
CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_KEY ,
306
- CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_DEFAULT_VALUE ,
306
+ computeDefaultSliceCount () ,
307
307
CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_DEFAULT_VALUE ,
308
308
Property .Dynamic ,
309
309
Property .NodeScope
310
310
);
311
-
312
311
// value 0 means rewrite filters optimization in aggregations will be disabled
313
312
@ ExperimentalApi
314
313
public static final Setting <Integer > MAX_AGGREGATION_REWRITE_FILTERS = Setting .intSetting (
@@ -1871,6 +1870,27 @@ public MinAndMax<?> estimatedMinAndMax() {
1871
1870
}
1872
1871
}
1873
1872
1873
+ /**
1874
+ * Computes the default maximum number of slices for concurrent segment search.
1875
+ * <p>
1876
+ * This value is dynamically calculated as:
1877
+ * <pre>
1878
+ * min(availableProcessors / 2, 4)
1879
+ * </pre>
1880
+ * This ensures that:
1881
+ * <ul>
1882
+ * <li>On small machines, it avoids over-threading.</li>
1883
+ * <li>On larger machines, it caps the concurrency to a reasonable level (4 slices).</li>
1884
+ * </ul>
1885
+ * This default is used when the user does not explicitly set the
1886
+ * {@code search.concurrent.max_slice_count} cluster setting.
1887
+ *
1888
+ * @return the computed default slice count
1889
+ */
1890
+ private static int computeDefaultSliceCount () {
1891
+ return Math .min (Runtime .getRuntime ().availableProcessors () / 2 , 4 );
1892
+ }
1893
+
1874
1894
/**
1875
1895
* This helper class ensures we only execute either the success or the failure path for {@link SearchOperationListener}.
1876
1896
* This is crucial for some implementations like {@link org.opensearch.index.search.stats.ShardSearchStats}.
0 commit comments