Products disappears from category pages but showing on homepage in product sliders, when you try to reindex products appears for 5 minutes then again disappears OR when you save any product they start appearing for 5 minutes the again disappears.
2 Answers
What actually happens if you have multiple instances on the same server and configured elastic search, the elastic search starts creating issue due to same index prefix, you should change the index prefix and try reindexing after that, Issue will resolve. I spend so much time to debug, this may save someone time.
-> Go to Store->Configuration->Catalog->Catalog->Catalog Search. -> Change Elasticsearch Index Prefix to something else e.g. (add any word) -> Save config and run reindexing.
This solved it in my case:
cd /path/to/your/magento/installation
sudo rm -rf generated/code/*
sudo -u www-data php bin/magento setup:di:compile
sudo -u www-data php bin/magento cache:clean
sudo -u www-data php bin/magento cache:flush
sudo -u www-data php bin/magento indexer:reindex
what is important here is to execute the commands with the user www-data and NOT with root.