Rebuild the whole index for this field.

        Parameters
        ----------
        chunk_size: int
            Default to 1000, it's the number of instances to load at once.
        aggressive_clear: bool
            Will be passed to the `aggressive` argument of the `clear` method.
            If `False`, all values will be normally deindexed. If `True`, the work
            will be done at low level, scanning for keys that may match the ones used by the index

        Examples
        --------

        >>> MyModel.get_field('myfield')._indexes[0].rebuild()

def rebuild(self, chunk_size=1000, aggressive_clear=False):
        """Rebuild the whole index for this field.

        Parameters
        ----------
        chunk_size: int
            Default to 1000, it's the number of instances to load at once.
        aggressive_clear: bool
            Will be passed to the `aggressive` argument of the `clear` method.
            If `False`, all values will be normally deindexed. If `True`, the work
            will be done at low level, scanning for keys that may match the ones used by the index

        Examples
        --------

        >>> MyModel.get_field('myfield')._indexes[0].rebuild()

        """
        assert self.attached_to_model, \
            '`rebuild` can only be called on an index attached to the model field'

        self.clear(chunk_size=chunk_size, aggressive=aggressive_clear)

        start = 0
        while True:
            instances = self.model.collection().sort().instances(skip_exist_test=True)[start:start + chunk_size]
            for instance in instances:
                field = instance.get_instance_field(self.field.name)
                value = field.proxy_get()
                if value is not None:
                    field.index(value, only_index=self)

            if len(instances) < chunk_size:  # not enough data, it means we are done
                break

            start += chunk_size