rebuild_index
Python シェルから実行すると、並べ替えで問題が発生することに気付きました。Bash からの実行rebuild_index
は正しいことを行います。
$ bin/manage rebuild_index
WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
Failed to clear Elasticsearch index: Non-OK status code returned (404) containing u'IndexMissingException[[my_index] missing]'.
All documents removed.
Indexing 40 components.
--
In [1]: from haystack.query import SearchQuerySet
In [2]: SearchQuerySet().order_by('name')
Out[2]: [<SearchResult: my_app.component (pk=u'2')>, <SearchResult: my_app.component (pk=u'1')>, <SearchResult: my_app.component (pk=u'5')>, <SearchResult: my_app.component (pk=u'4')>, <SearchResult: my_app.component (pk=u'3')>, <SearchResult: my_app.component (pk=u'6')>, <SearchResult: my_app.component (pk=u'7')>, <SearchResult: my_app.component (pk=u'8')>, <SearchResult: my_app.component (pk=u'9')>, <SearchResult: my_app.component (pk=u'11')>, <SearchResult: my_app.component (pk=u'14')>, <SearchResult: my_app.component (pk=u'13')>, <SearchResult: my_app.component (pk=u'15')>, <SearchResult: my_app.component (pk=u'19')>, <SearchResult: my_app.component (pk=u'20')>, <SearchResult: my_app.component (pk=u'21')>, <SearchResult: my_app.component (pk=u'22')>, <SearchResult: my_app.component (pk=u'23')>, <SearchResult: my_app.component (pk=u'24')>, '...(remaining elements truncated)...']
In [3]: from django.core import management
In [4]: management.call_command('rebuild_index', interactive=False, verbosity=0)
Failed to clear Elasticsearch index: Non-OK status code returned (404) containing u'IndexMissingException[[my_index] missing]'.
In [5]: SearchQuerySet().order_by('name')
Failed to query Elasticsearch using '*:*': Non-OK status code returned (500) containing u'SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[SkgxFvdjRgyoiHv2qSpfbQ][my_index][4]: QueryPhaseExecutionException[[my_index][4]: query[filtered(ConstantScore(NotDeleted(cache(QueryWrapperFilter(django_ct:my_app.component)))))->cache(_type:modelresult)],from[0],size[20],sort[<custom:"name": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@3cb9b947>]: Query Failed [Failed to execute main query]]; nested: IOException[Can\'t sort on string types with more than one value per doc, or more than one token per field]; }{[SkgxFvdjRgyoiHv2qSpfbQ][my_index][0]: QueryPhaseExecutionException[[my_index][0]: query[filtered(ConstantScore(NotDeleted(cache(QueryWrapperFilter(django_ct:my_app.component)))))->cache(_type:modelresult)],from[0],size[20],sort[<custom:"name": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@249cf580>]: Query Failed [Failed to execute main query]]; nested: IOException[Can\'t sort on string types with more than one value per doc, or more than one token per field]; }{[SkgxFvdjRgyoiHv2qSpfbQ][my_index][3]: QueryPhaseExecutionException[[my_index][3]: query[filtered(ConstantScore(NotDeleted(cache(QueryWrapperFilter(django_ct:my_app.component)))))->cache(_type:modelresult)],from[0],size[20],sort[<custom:"name": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@4ff80724>]: Query Failed [Failed to execute main query]]; nested: IOException[Can\'t sort on string types with more than one value per doc, or more than one token per field]; }{[SkgxFvdjRgyoiHv2qSpfbQ][my_index][2]: QueryPhaseExecutionException[[my_index][2]: query[filtered(ConstantScore(NotDeleted(cache(QueryWrapperFilter(django_ct:my_app.component)))))->cache(_type:modelresult)],from[0],size[20],sort[<custom:"name": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@99b8b51>]: Query Failed [Failed to execute main query]]; nested: IOException[Can\'t sort on string types with more than one value per doc, or more than one token per field]; }{[SkgxFvdjRgyoiHv2qSpfbQ][my_index][1]: QueryPhaseExecutionException[[my_index][1]: query[filtered(ConstantScore(NotDeleted(cache(QueryWrapperFilter(django_ct:my_app.component)))))->cache(_type:modelresult)],from[0],size[20],sort[<custom:"name": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@42d777c4>]: Query Failed [Failed to execute main query]]; nested: IOException[Can\'t sort on string types with more than one value per doc, or more than one token per field]; }]'.
Out[5]: []
Elasticsearch-head フロントエンドを使用してインデックス メタデータを調べました。実行したシェルによって設定構造が異なることがわかりましたrebuild_index
。
良いバージョン ( rebuild_index
Bash から実行):
settings: {
index.analysis.filter.haystack_ngram.type: nGram
index.analysis.tokenizer.haystack_edgengram_tokenizer.type: edgeNGram
index.analysis.analyzer.edgengram_analyzer.filter.0: haystack_edgengram
index.analysis.filter.haystack_edgengram.min_gram: 2
index.analysis.tokenizer.haystack_edgengram_tokenizer.side: front
index.analysis.filter.haystack_edgengram.type: edgeNGram
index.analysis.filter.haystack_ngram.max_gram: 15
index.analysis.analyzer.edgengram_analyzer.type: custom
index.analysis.tokenizer.haystack_ngram_tokenizer.max_gram: 15
index.analysis.tokenizer.haystack_ngram_tokenizer.type: nGram
index.analysis.tokenizer.haystack_edgengram_tokenizer.max_gram: 15
index.analysis.tokenizer.haystack_edgengram_tokenizer.min_gram: 2
index.analysis.analyzer.ngram_analyzer.filter.0: haystack_ngram
index.analysis.analyzer.ngram_analyzer.tokenizer: lowercase
index.analysis.tokenizer.haystack_ngram_tokenizer.min_gram: 3
index.analysis.filter.haystack_ngram.min_gram: 3
index.analysis.analyzer.ngram_analyzer.type: custom
index.analysis.analyzer.edgengram_analyzer.tokenizer: lowercase
index.analysis.filter.haystack_edgengram.max_gram: 15
index.number_of_shards: 5
index.number_of_replicas: 1
index.version.created: 190999
}
悪いバージョン ( rebuild_index
Python シェルから実行):
settings: {
index.number_of_shards: 5
index.number_of_replicas: 1
index.version.created: 190999
}
それらすべてのindex.analysis.*
鍵は何ですか?彼らはどこから来たのか?
Haystack チケット: https://github.com/toastdriven/django-haystack/issues/645