def __init__(self, filter_class):
     """
     Initialize this filter component to have a reference to the class that it should filter
     upon.
     :param filter_class: The Elasticsearch model class to filter on.
     """
     ValidationHelper.validate_es_model_class(filter_class)
     self._filter_class = filter_class
Exemple #2
0
 def search_model(self, model_class=None, *args, **kwargs):
     """
     Search an index for the referenced model type using the Elasticsearch query DSL.
     :param model_class: A model class to search for.
     :param args: Positional arguments for elasticsearch.search.
     :param kwargs: Keyword arguments for elasticsearch.search.
     :return: The result of elasticsearch.search.
     """
     ValidationHelper.validate_es_model_class(model_class)
     kwargs["doc_type"] = model_class.get_doc_type()
     return self.search_index(*args, **kwargs)
Exemple #3
0
 def update_mapping_for_model(self, model_class=None, index=None):
     """
     Update the document type mapping for the document represented by the given model class.
     :param model_class: The model class to update the mappings for.
     :param index: The index to update the mapping in.
     :return: None
     """
     ValidationHelper.validate_es_model_class(model_class)
     self.connection.indices.put_mapping(
         model_class.get_doc_type(),
         index=index,
         body=model_class.get_mapping_dict(),
     )
Exemple #4
0
 def update_mapping_for_models(self, model_classes=None, index=None):
     """
     Update the document type mapping for the documents represented by the given model classes.
     :param model_classes: A list of Elasticsearch model classes to update the mappings for the
      given index for.
     :param index: The index to update mappings for.
     :return: The Elasticsearch response.
     """
     body = {"mappings": {}}
     for model_class in model_classes:
         ValidationHelper.validate_es_model_class(model_class)
         body["mappings"][model_class.get_doc_type()] = model_class.get_mapping_dict()
     return self.connection.indices.put_mapping(
         None,
         index=index,
         body=body,
     )