我正在使用Haystack 2.3.1並試圖找出多個索引。django-haystack與彈性搜索不建設索引新增索引模型
我已經在HAYSTACK_CONNECTIONS中設置並定義了elasticsearch核心,然後我在search_indexes.py中創建了三個SearchIndexes。
當我運行命令manage.py rebuild_index時,我看到這個警告。
感謝您的任何提示,讓我知道如果我失去了什麼。
setting.py:
```
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'default',
'TIMEOUT': 60 * 5,
'INCLUDE_SPELLING': True,
'SILENTLY_FAIL': True,
'EXCLUDED_INDEXES': ['dmmactress.search_indexes.ActressInfoIndex'],
},
'autocomplete': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'autocomplete',
'TIMEOUT': 60 * 5,
'INCLUDE_SPELLING': True,
'SILENTLY_FAIL': True,
'EXCLUDED_INDEXES': ['dmmactress.search_indexes.EnActress'],
},
'autocomplete2': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'autocomplete2',
'TIMEOUT': 60 * 5,
'INCLUDE_SPELLING': True,
'SILENTLY_FAIL': True,
'EXCLUDED_INDEXES': ['dmmactress.search_indexes.EnMovielist'],
},
}
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
```
search_indexes.py
```
class ActressInfoIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
name = indexes.CharField(model_attr='name')
birth = indexes.CharField(model_attr='birth')
starsign = indexes.CharField(model_attr='starsign')
bloodtype = indexes.CharField(model_attr='bloodtype')
boobs = indexes.CharField(model_attr='boobs')
home = indexes.CharField(model_attr='home')
hobby = indexes.CharField(model_attr='hobby')
image_paths = indexes.CharField(model_attr='image_paths')
def get_model(self):
return ActressInfo
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all()
class EnActress(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
name = indexes.CharField(model_attr='name')
image_paths = indexes.CharField(model_attr='image_paths')
def get_model(self):
return EnActress
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all()
class EnMovielist(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
Content_ID = indexes.CharField(model_attr='Content_ID')
release_date = indexes.CharField(model_attr='release_date')
running_time = indexes.CharField(model_attr='running_time')
Actress = indexes.CharField(model_attr='Actress')
Series = indexes.CharField(model_attr='Series')
Studio = indexes.CharField(model_attr='Studio')
Director = indexes.CharField(model_attr='Director')
Label = indexes.CharField(model_attr='Label')
image_paths = indexes.CharField(model_attr='image_paths')
def get_model(self):
return EnMovielist
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all()
```
_text.txt
```
{{ object.name}}
{{ object.image_paths }}
{{ object.birth }}
{{ object.starsign }}
{{ object.bloodtype }}
{{ object.boobs }}
{{ object.home }}
{{ object.hobby }}
{{ object.EnMovielist.Content_ID }}
{{ object.EnMovielist.image_paths }}
{{ object.EnMovielist.release_date }}
{{ object.EnMovielist.running_time }}
{{ object.EnMovielist.Actress }}
{{ object.EnMovielist.Series }}
{{ object.EnMovielist.Studio }}
{{ object.EnMovielist.Director }}
{{ object.EnMovielist.Label }}
{{ object.EnActress.name}}
{{ object.EnActress.image_paths }}
```
..after運行
Indexing 9464 actress infos GET /autocomplete/_mapping [status:404 request:0.001s] Indexing 9464 actress infos GET /autocomplete2/_mapping [status:404 request:0.003s]
你爲什麼定義了三個相同的後端?定義指向同一個Elasticsearch集羣的多個後端沒有意義。 – solarissmoke