def add_model_for_indexing(self, model=None, index=None): """ Add the given model to the batch queue to be indexed. :param model: The model to add to the batch queue. :param index: The index the model should be indexed within. :return: None """ ValidationHelper.validate_es_model_type(model) self._batch_queue.append(("index", index, model))
def index_model(self, model=None, *args, **kwargs): """ Create and index a new Elasticsearch document based on the contents of model. :param model: An instance of an Elasticsearch model to index. :param args: Positional arguments for elasticsearch.index. :param kwargs: Keyword arguments for elasticsearch.index. :return: The result of indexing the given document. """ ValidationHelper.validate_es_model_type(model) kwargs["body"] = model.to_es_dict() kwargs["doc_type"] = model.doc_type return self.index_document(*args, **kwargs)
def update_model(self, model=None, index=None, *args, **kwargs): """ Perform an update for the document associated with the given model in the given index. :param model: An instance of an Elasticsearch model class to perform the update based on. :param index: The index to perform the update in. :param args: Positional arguments for the Elasticsearch update method. :param kwargs: Keyword arguments for the Elasticsearch update method. :return: The Elasticsearch response. """ ValidationHelper.validate_es_model_type(model) kwargs["index"] = index kwargs["doc_type"] = model.doc_type kwargs["id"] = model.id kwargs["body"] = { "doc": model.to_es_dict(), } return self.connection.update(*args, **kwargs)