Index through multiple models through django-elasticsearch-dsl

62 Views Asked by At

I am trying to create an index which would be used to autocomplete, and basically stores the aggregation of three model field

These are my models below

class SmallShop(models.Model):
    small_name = models.TextField(blank=True, null=True)
    small_address = models.TextField(max_length=255, null=True)

class MediumShop(models.Model):
    medium_name = models.TextField(blank=True, null=True)
    medium_address = models.TextField(max_length=255, null=True)


class BigShop(models.Model):
    big_name = models.TextField(blank=True, null=True)
    big_address = models.TextField(max_length=255, null=True)

This my documents.py file

class AddressAutosuggestionDocument(Document): 
    address = fields.TextField()

    class Index:
        name = "address_autosuggestion"
        settings = {"number_of_shards": 1, "number_of_replicas": 0}
    
    class Django:
        model = SmallShop # <- Here I want to have multiple/all models of shop that I listed above 

    def prepare_address(self, instance):
        return instance.small_address <- Based on the model I also want to pick its field for ingestion in the doc field

I tried joining quertysets for models but I couldn't figure out how to provide custom queryset

0

There are 0 best solutions below