Using search api programatically I have read and tried https://www.drupal.org/docs/8/modules/search-api/developer-documentation/executing-a-search-in-code

I am using drupal 8 and using the default content index for testing. I am able to run the following code and I get a result count, but not result items.

$index = \Drupal\search_api\Entity\Index::load('default_index');
$query = $index-&gt;query();

// Change the parse mode for the search.
$parse_mode = \Drupal::service('plugin.manager.search_api.parse_mode')
  -&gt;createInstance('direct');
$parse_mode-&gt;setConjunction('OR');
$query-&gt;setParseMode($parse_mode);

// Set fulltext search keywords and fields.
$query-&gt;keys('');
$query-&gt;setFulltextFields(['title', 'name', 'body']);

// Do paging.
$query-&gt;range(20, 10);

// Set one or more tags for the query.
// @see hook_search_api_query_TAG_alter()
// @see hook_search_api_results_TAG_alter()
$query-&gt;addTag('custom_search');

// Execute the search.
$results = $query-&gt;execute();

echo "Result count: {$results-&gt;getResultCount()}\n";
$ids = implode(', ', array_keys($results-&gt;getResultItems()));
echo "Returned IDs: $ids.\n";


Count shows a value but I can't get any result items.
I tried with $query->keys(''); $query->keys('*'); and some value $query->keys('some value');
In all cases the count seems to be correct. The search therefore seems to be executed correctly, but how can I retrieve the items?
//first just run this line
    kint($results);
    //and then you can uncomment the next lines, in my case I needed the response key 'elasticsearch_response'
    $response = $results-&gt;getExtraData('elasticsearch_response', []);
    $hits = $response['hits']['hits'];
    foreach($hits as $hit){
      kint($hit);
    }