Deleting duplicates in index using API query

Please do not open multiple threads on the same topic. This has already been asked and answered here and here.