<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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 -------- """

        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