Steps to reproduce

  1. Have a Typesense collection with indexed documents (e.g., 80k+ products)
  2. Add a new field to the Search API index configuration (search_api.index.*.yml)
  3. Run drush cim or drush deploy
  4. 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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

petar.gnjidic created an issue. See original summary.

petar.gnjidic’s picture

StatusFileSize
new5.96 KB
lussoluca’s picture

Thanks, Petar!
We were thinking about this feature exactly yesterday. Can you please create a merge request for this?

petar.gnjidic changed the visibility of the branch 3563399-updateindex-drops-collection to hidden.

petar.gnjidic’s picture

Thanks Luca! I've created a merge request for this.
Glad to contribute to the community and the module.

giuseppe87 made their first commit to this issue’s fork.

lussoluca’s picture

Assigned: petar.gnjidic » Unassigned
Status: Active » Fixed

Released in 1.2.0-beta3, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

lussoluca’s picture

Released in 1.2.0-beta3, thanks!