Template migration from parent-child to nested give java heap memory issue

Hello,
We are in a process of upgrading our elasticsearch version and for that we decided to convert existing parent-child template_mapping to nested. During this process one of the scenario where more 10000 nested objects gets updated to a parent record is failing(which was working during parent-child mapping). The error we get is java heap out of memory exception(currently we use 1g of HEAP but tried increasing it to 5g but still fails). I am suspecting that the issue is caused by nested object updates as it causes re-indexing for every nested object update. When I try with 1000 records it works fine.

java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid28.hprof ...
Unable to create java_pid28.hprof: Permission denied

any thoughts on this?