Search code examples
elasticsearchwagtail

Is it possible to "temporarily" disable search indexing for a model?


So I know I can put search_auto_update = False on the Model in question, however I dont want to turn off indexing entirely.

https://docs.wagtail.org/en/v2.13.5/topics/search/indexing.html#disabling-auto-update-signal-handlers-for-a-model

I have a command which bulk syncs data from an API. Currently, on every Save, it's also triggering and index; this is inefficient and slow. It would make a lot more sense to disable indexing during the sync and then bulk-index the items at the end.

Is this possible? I tried setting search_auto_update as an key/value on the model before save, but it didn't seem to do anything (it looks like it needs to be an attribute on the class, rather than a model instance value).


Solution

  • The search indexing on save is done via signals, so I think this SO answer for how to temporarily disable signals should work. In short, use FactoryBoy's mute_signals decorator