For indexing to be done automatically in Magento, you must ensure that you are using the indexing queue. Ensure that you have configure it as explained in this guide. After enabling it, you can set up a crontab or other process to automatically run the indexing operation.