Deleting and re-index an elasticsearch index in Laravel

50 0 0 0

Last Updated : 2020-10-20 20:58:14

If you need to change the mapping of an elasticsearch index, then you have to remove it first and then re-create and re-index it again. Here is how you can do this in a Laravel application.


  1. To remove an elasticsearch index, using postman:
    http://localhost:9200/federalbills/​


  2. To re-create the index again in your Gitbash console:
    php artisan elastic:create-index App\\ElasticsearchIndexConfigurators\\FederalBillIndexConfigurator​


  3. If you need to create the searchable model, if not exist (This is optional, because it almost have been done previously):
    php artisan make:searchable-model MyModel --index-configurator=MyIndexConfigurator​


  4. to re-index the data again:
    php artisan scout:import "App\Bill"​


  5.  

Mohammed Anwar

Mohammed Anwar

Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .