Deleting and re-index an elasticsearch index in Laravel

80 0 0 0

Last Updated : 2021-01-18 14:46:18

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. To create an index in a simple way:
    //PUT
    https://search-alpha-ejy342scj7a3coqfhhtkopoh5u.us-east-2.es.amazonaws.com/newIndexname ​


  6. In order to create the federaleventsfiles or provincialeventsfiles indices, you have first to create the index as named using put method from postman without any mapping, this is acceptable. and mentioned in the previous step #5. Then you have to create the attachment pipeline as follows :
    //PUT
    https://search-alpha-ejy342scj7a3coqfhhtkopoh5u.us-east-2.es.amazonaws.com/_ingest/pipeline/attachment?pretty

    // Now, in the body in postmap use raw and JSON and add this :

    {
    "description" : "Extract attachment information encoded in Base64 with UTF-8 charset",
    "processors" : [
    {
    "attachment" : {
    "field" : "content",
    "indexed_chars" : -1
    }
    }
    ]
    }​


  7. -

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 .