I want to run Cron job to reindex indexer in Magento 2. Please provide the solution with a code.
You can run the following command from CLI form the bin directory:
./magento cron:run
"One or more indexers are invalid. Make sure your Magento cron job is running"
Goto the cli
cd /Applications/MAMP/htdocs/magento/bin/
>./magento indexer:reindex
Output
Design Config Grid index has been rebuilt successfully in 00:00:01 Customer Grid index has been rebuilt successfully in 00:00:02 Category Products index has been rebuilt successfully in 00:00:04 Product Categories index has been rebuilt successfully in 00:00:00 Product Price index has been rebuilt successfully in 00:00:13 Product EAV index has been rebuilt successfully in 00:00:03 Catalog Search index has been rebuilt successfully in 00:00:10 Stock index has been rebuilt successfully in 00:00:01 Catalog Rule Product index has been rebuilt successfully in 00:00:09
Catalog Product Rule index has been rebuilt successfully in 00:00:00
and then
./magento cron:run