We are currently investigating a pre-indexing method and not to generate the index on the fly. This case only happens in migration scenarios where it wasn't able to build up an index in the first place.
@WalterH is correct, some more explanation:
Enriching the request_terminate_timeout to a higher value and enlarging the memory_limit for PHP does the job. This is required for the first index to build up correctly which is done with the first search. If the first search happens to have a large unindexed amount of data, it requires some more seconds (and memory) to build up the very first time.
We think it makes sense to be able to create these indexes additionally another way, not offloading the (grommunio web only) index to web only.