yunojuno/elasticsearch-django

Allow greater control over model updates forcing an update

hugorodgerbrown opened this issue · 1 comments

The automated signal-attached model updates have a single ON/OFF control switch. In some situations this results in a high frequency of updates when not strictly necessary (e.g. a model field that is not indexed being changed and the model saved will result in an update being sent even if the document hasn't changed (caching aside).

It would be good to be able to intercept this process with a custom function that returns True/False to determine whether to update or not.

In fact you can already do this by overriding the update_search_index method:

class MyClass(SearchDocumentMixin, models.Model):

    ...

    def update_search_index(self, action, index='_all', force=False):
        if self.foo() not force:
            logger.debug("Ignoring search index update as foo is False.")
            return
        super().update_search_index(action, index=index, force=force)