How can I get additional fields from Search API query? I have Search API DB backend where I will be retrieving thousands of results and I need some fields to get out of there as well, beside search item id, since doing additional query to MySQL with IN condition consisting of thousands of entries is nonsense.

Can't find any methods to do this in the code so far though.

I think the query option search_api_retrieved_properties is the key, but I was not able to make it work yet.



I have added the fields via hook_search_api_db_query_alter on tagged query but they are not present. Calling getField() on the result item always queries the source entity(= entity_load operation).
Unfortunately, it looks like this is impossible.

Looking at \Drupal\search_api_db\Plugin\search_api\backend\Database::search:

  $result = $db_query-&gt;execute();

  foreach ($result as $row) {
    $item = $this-&gt;getFieldsHelper()-&gt;createItem($index, $row-&gt;item_id);
    $item-&gt;setScore($row-&gt;score / self::SCORE_MULTIPLIER);
    $results-&gt;addResultItem($item);
  }


The $item will receive only the item_id from the fetched row, so all added fields are lost :(