Haystack Multiple Indices - indexed same even there are different search_indexes

◇◆丶佛笑我妖孽 提交于 2019-12-10 18:59:15

问题


I have the following search

class ProductIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    destination = indexes.FacetIntegerField(
        model_attr='hotel__destination__id')
    country = indexes.FacetIntegerField(model_attr='hotel__country__id')
    hotel_class = indexes.FacetCharField(model_attr='hotel__hotel_class')
    hotel_type = indexes.FacetIntegerField(model_attr='hotel__hotel_type__id')


    def get_model(self):
        return Product

    def index_queryset(self, using=True):
        return self.get_model().objects.all()



class DestinationIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    content_auto = indexes.EdgeNgramField(model_attr="foo")

And following settings in settings.py

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE':
        'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'haystack',
    },
    'autocomplete': {
        'ENGINE':
        'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'autcomplete',
    }
}

But when I say rebuild_indexes, two index become the same, they index according to both index classes. But I want default index to be indexed with ProductIndex and autocomplete to be indexed with Destination index.

Any ideas?


回答1:


You can exclude indexes using key EXCLUDED_INDEXES:

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE':
        'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'haystack',
        'EXCLUDED_INDEXES': ['my_destination_app.search_indexes.DestinationIndex'],
    },
    'autocomplete': {
        'ENGINE':
        'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'autcomplete',
        'EXCLUDED_INDEXES': ['my_product_app.search_indexes.ProductIndex'],
    }
}


来源:https://stackoverflow.com/questions/17233752/haystack-multiple-indices-indexed-same-even-there-are-different-search-indexes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!