干草堆多个索引-即使有不同的search_indexes索引相同 [英] Haystack Multiple Indices - indexed same even there are different search_indexes

查看:126
本文介绍了干草堆多个索引-即使有不同的search_indexes索引相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下搜索

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

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

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

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.

有什么想法吗?

推荐答案

您可以使用键 EXCLUDED_INDEXES 排除索引:

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'],
    }
}

这篇关于干草堆多个索引-即使有不同的search_indexes索引相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆