Update a model in the registry (create if needed)
        :param name: name for the model
        :param datapackage_url: origin URL for the datapackage which is the
            source for this model
        :param datapackage: datapackage object from which this model was
            derived
        :param dataset_name: Title of the dataset
        :param author: Author of the dataset
        :param model: model to save
        :param status: What's the status for loading
        :param loaded: Was the package loaded successfully

def update_model(self, name, **kw):
        """
        Update a model in the registry (create if needed)
        :param name: name for the model
        :param datapackage_url: origin URL for the datapackage which is the
            source for this model
        :param datapackage: datapackage object from which this model was
            derived
        :param dataset_name: Title of the dataset
        :param author: Author of the dataset
        :param model: model to save
        :param status: What's the status for loading
        :param loaded: Was the package loaded successfully
        """

        # If `model` or `datapackage` in kw args, completely remove respective
        # field from the ES item, so it can be replaced below (rather than
        # merged).
        if 'model' in kw:
            body_remove_model = \
                '{"script" : "ctx._source.remove(\u0027model\u0027)"}'
            self.es.update(index=self.index_name, doc_type=self.DOC_TYPE,
                           body=body_remove_model, id=name)

        if 'datapackage' in kw:
            body_remove_datapackage = \
                '{"script" : "ctx._source.remove(\u0027package\u0027)"}'
            self.es.update(index=self.index_name, doc_type=self.DOC_TYPE,
                           body=body_remove_datapackage, id=name)

        document = {
            'id': name,
            'last_update': time.time()
        }
        for key, param in [
                ('model', 'model'),
                ('package', 'datapackage'),
                ('origin_url', 'datapackage_url'),
                ('dataset', 'dataset_name'),
                ('author', 'author'),
                ('loading_status', 'status'),
                ('loaded', 'loaded')]:
            if param in kw:
                document[key] = kw[param]

        body = dict(
            doc=document,
            doc_as_upsert=True
        )
        self.es.update(index=self.index_name, doc_type=self.DOC_TYPE,
                       body=body, id=name)
        # Make sure that the data is saved
        self.es.indices.flush(self.index_name)
        # Clear the api cache (if api_cache isn't None)
        try:
            api_cache.clear(name)
        except AttributeError:
            pass