how to restrict posts_request filter to the main query only

The posts_request filter actually takes a second argument, which is the query. You can check if that query is the main query. Try this:

add_filter( 'posts_request', 'my_request_filter', 10, 2 );

function my_request_filter($sql, $query) {
    if($query->is_main_query() && is_search()) {
        $sql="some custom sql query"
    }
    return $sql;
}