3

我有以下搜索

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")

并在 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',
    }
}

但是当我说rebuild_indexes 时,两个索引变得相同,它们根据两个索引类进行索引。但我希望使用 ProductIndex 索引默认索引,并使用 Destination index 索引自动完成。

有任何想法吗?

4

1 回答 1

8

您可以使用 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'],
    }
}
于 2013-10-14T14:25:33.863 回答