liberation / django-elasticsearch

Simple wrapper around elasticsearch-py to index/search a django Model.
MIT License
212 stars 73 forks source link

Add "exclude_fields" to class Elasticsearch #70

Open sadnoodles opened 7 years ago

sadnoodles commented 7 years ago

Can you add a exclude_fields to class Elasticsearch to only exclude some fields?

I'm using abstract model. I have a lot of models have a uuid field (and other fields) which is useless for search. Its painfull to use fields to specify each model to exclude the uuid field.

My code like this:

class CommonAttr(models.Model):
    create_date = models.DateTimeField(u"Create data", auto_now_add=True) # exclude
    uuid = models.CharField(u'UUID', max_length=36, unique=True) # exclude

    class Meta:
        abstract = True

    class Elasticsearch(EsIndexable.Elasticsearch):
        exclude_fields = ['uuid',  'create_date']  # this is very usefull for abstract model

class A(CommonAttr):
    pass

class B(CommonAttr):
    pass

Can you add a exclude_fields to only exclude some fields? Thank you very much.