diff --git a/django_elasticsearch/managers.py b/django_elasticsearch/managers.py index edf2718..42ad496 100644 --- a/django_elasticsearch/managers.py +++ b/django_elasticsearch/managers.py @@ -245,7 +245,11 @@ def get_fields(self): model_fields = [f.name for f in self.model._meta.fields + self.model._meta.many_to_many] - return self.model.Elasticsearch.fields or model_fields + ret = self.model.Elasticsearch.fields or model_fields + excludes = self.model.Elasticsearch.exclude_fields + if excludes: + ret = [i for i in ret if i not in excludes] + return ret def make_mapping(self): """ diff --git a/django_elasticsearch/models.py b/django_elasticsearch/models.py index 39ab19f..d975b77 100644 --- a/django_elasticsearch/models.py +++ b/django_elasticsearch/models.py @@ -31,6 +31,7 @@ class Elasticsearch: mapping = None serializer_class = EsJsonSerializer fields = None + exclude_fields = None facets_limit = 10 facets_fields = None # http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-term.html diff --git a/readme.md b/readme.md index 55b19ba..7994e28 100644 --- a/readme.md +++ b/readme.md @@ -115,6 +115,24 @@ Each EsIndexable model receive an Elasticsearch class that contains its options Defaults to None The fields to be indexed by elasticsearch, if left to None, all models fields will be indexed. +* **exclude_fields** + Defaults to None + Exclude those fields to index, if left to None, exclude is disabled. + Example: + + ```python + MyModel(EsIndexable, models.Model): + useful_for_search = models.CharField(max_length=64) + no_use_for_search = models.CharField(max_length=64) + + class Elasticsearch(EsIndexable.Elasticsearch): + fields = ['useful_for_search'] + exclude_fields = {'no_use_for_search',} #allow set, list, tuple. set is the best. + ``` + + + + * **mappings** Defaults to None You can override some or all of the fields mapping with this dictionary