Steps to reproduce
- Have a Typesense collection with indexed documents (e.g., 80k+ products)
- Add a new field to the Search API index configuration (search_api.index.*.yml)
- Run
drush cim or drush deploy
- Observe that Typesense collection is empty - all documents are lost
Root cause: SearchApiTypesenseBackend::updateIndex() calls removeIndex() which drops the entire collection. The exportCollectionData() method only exports synonyms/curations, NOT the actual documents.
Proposed resolution
Use Typesense's PATCH API to update schema without dropping the collection.
The patch:
- Adds
updateCollectionSchema() method to TypesenseClient using PATCH API
- Modifies
updateIndex() to compare schemas and only add/remove changed fields
- Preserves all existing documents
- Only triggers
reindex() when new fields are added (to populate their data)
- Re-throws exceptions instead of silently logging them
See: Typesense PATCH API docs
Remaining tasks
- Review patch
- Test with different field types
- Commit
User interface changes
None.
API changes
New method added to TypesenseClientInterface:
public function updateCollectionSchema(string $collection_name, array $fields_to_add, array $fields_to_drop): void;
Data model changes
None.
Comments
Comment #2
petar.gnjidic commentedComment #3
lussolucaThanks, Petar!
We were thinking about this feature exactly yesterday. Can you please create a merge request for this?
Comment #6
petar.gnjidic commentedThanks Luca! I've created a merge request for this.
Glad to contribute to the community and the module.
Comment #11
lussolucaReleased in 1.2.0-beta3, thanks!
Comment #13
lussolucaReleased in 1.2.0-beta3, thanks!