Re-indexing Process
This content is for v3.9. Switch to the latest version for up-to-date documentation.
Missed Mapping
To create a real-world scenario, let’s consider a site log system that stores the URL, user IP, and location of visitors.
We’ll intentionally overlook the mapping of the location
field, which should be mapped as a geo_point
type.
Assuming there’s a model for this index, you create a record like so:
After some time, you realize that the location
field should be mapped as a geo_point
type. If you try to filter records based on the location
field, you’ll get an error because the field is not correctly mapped.
Re-indexing
-
Create a Temporary Index with Correct Mapping
Create a temporary index with the correct mapping for the location field.
-
Re-indexing Data to the Temporary Index
Copy all records from the original site_logs index to the temp_site_logs index.
NB: Verify the success of the re-indexing operation, analyze
$result->data
for any errors and make sure all the collections were copied to the new index. -
Delete the Original Index
Once you’ve confirmed that all data has been successfully copied, delete the original index.
-
Recreating the Original Index with Correct Mapping
Now, recreate the
site_logs
index with the correct mappings. -
Re-indexing Data Back to the Original Index
Copy the data from the temporary index back to the original index.
Again, verify the success of the re-indexing operation:
-
Verifying the Correct Functionality
Now, with the location field correctly mapped, filtering operations should work as expected.
If there is an issue then delete the index and go back to step 4
-
Delete the Temporary Index
Finally, delete the temporary index.