Adding post fields in wp-json/wp/v2/search

For the search endpoint, the object type (the first parameter for register_rest_field()) is search-result and not the post type (e.g. post, page, etc.).

So try with this, which worked for me:

add_action( 'rest_api_init', function () {
    // Registers a REST field for the /wp/v2/search endpoint.
    register_rest_field( 'search-result', 'excerpt', array(
        'get_callback' => function ( $post_arr ) {
            return $post_arr['excerpt'];
        },
    ) );
} );

tech