Elastic search to Postgres migration and building Cache for trillions records

If data is coming out of Elasticsearch faster than it can go into Postgres it sounds to me like the problem is with Postgres. If that is the case I do not think we can help here.

What analysis are you doing in Postgres that you can not do in Elasticsearch? Might it be possible to simplify the whole process?