facetwp index only 1st level children in taxonomy

<?php
/** index only first level children terms, no grandchildren or deeper **/
add_filter( 'facetwp_index_row', function( $params ) {
    if ( 'product_categories' == $params['facet_name'] ) { //change 'product_categories' to name of your facet
		if ( '1' != $params['depth'] ) { // adjust comparison as needed for different child levels
			$params['facet_value'] = ''; // skip indexing
		}
	}
	return $params;
});