Ravi Kumar
Ravi Kumar

Reputation: 1797

Django-haystack: creating search index with multiple models

I started experiments on Django-haystack and elastic search.

using:

django-haystack==2.4.0
elasticsearch==1.6.0

models.py

class Skill(models.Model):
    name = models.CharField(max_length=100)

class City(models.Model):
    name = models.CharField(max_length=100)

I want to create one search index for above models:

class multiIndex(indexes.SearchIndex, indexes.Indexable):
    #other code
    def get_model(self):
        return (Skill, City)

is it possible to create search index with multiple models. or i have to create multiple search indexes for multiple models.

Note: both models are completely independent.

Upvotes: 3

Views: 959

Answers (1)

François Constant
François Constant

Reputation: 5496

You cannot create one SearchIndex for multiple models; you are not meant to. If your models are similar you could use some inheritance though (but I reckon that Skill & City don't have much in common).

You are meant to create SkillIndex & CityIndex.

You can search them together; I guess that's what you want to do, isn't it?

Upvotes: 2

Related Questions