Export all records from 12M index

the problem is with the index.max_result_window,
we have an index of 12M records , how can we query/get all data using a script?

(logstash not relevant)

Use scan and scroll - Scan and scroll | Elasticsearch Guide [7.12] | Elastic

We no longer recommend using the scroll API for deep pagination. If you need to preserve the index state while paging through more than 10,000 hits, use the search_after parameter with a point in time (PIT).