I reordered the search logic a bit and included a bit better filtering before the costly aggregations are run. Also lowered the maximum result size from 5M to 500k. If this does not improve the situation, we can still lower the query size. But I would not spend much more time optimizing these queries as they will anyways go away once we get the materials index up.