如何修复错误"The [standard] token filter has been removed"?



我正在尝试将一个项目从ElasticSearch 2.3与NEST 2.5.8版本升级到ElasticSearch 7.9与NEST 7.11.1。当我尝试创建索引时,我得到错误:

# OriginalException: Elasticsearch.Net.ElasticsearchClientException: The remote server returned an error: (400) Bad Request.. Call: Status code 400 from: PUT /partsearch.01. ServerError: Type: illegal_argument_exception Reason: "failed to build synonyms" CausedBy: "Type: parse_exception Reason: "Invalid synonym rule at line 1" CausedBy: "Type: illegal_argument_exception Reason: "The [standard] token filter has been removed."""

当这个错误发生时,试图创建索引的代码是:

protected internal CreateIndexResponse CreateIndex(string name)
{
var indicesOperationResponse = this.elasticClientProxy.CreateIndex(
name, c => c
.Settings(
s => s
.NumberOfReplicas(this.numberOfReplicas)
.NumberOfShards(this.numberOfShards)
.Setting("index.max_result_window", this.maxResultWindow)
.Analysis(
ad => ad
.CharFilters(this.RegisterCharFilters)
.Tokenizers(this.RegisterTokenizers)
.TokenFilters(this.RegisterTokenFilters)
.Analyzers(this.RegisterAnalyzers)))
.Map<T>(this.Map)
.Map<IndexMetaData>(this.MapIndexMetaData));
return indicesOperationResponse;
}

RegisterTokenFilters的实现是:

protected internal override TokenFiltersDescriptor RegisterTokenFilters(TokenFiltersDescriptor descriptor)
{
return descriptor.UserDefined(TokenFilter.NormalizeNumberSeparator.DisplayName, TokenFilter.NormalizeNumberSeparator.Filter)
.UserDefined(TokenFilter.CustomStopWordFilter.DisplayName, TokenFilter.CustomStopWordFilter.Filter)
.UserDefined(TokenFilter.StripNumberUnit.DisplayName, TokenFilter.StripNumberUnit.Filter)
.UserDefined(TokenFilter.StripEndingPunctuation.DisplayName, TokenFilter.StripEndingPunctuation.Filter)
.UserDefined(TokenFilter.StripCommaFromNumber.DisplayName, TokenFilter.StripCommaFromNumber.Filter)
.UserDefined(TokenFilter.EnglishStemmer.DisplayName, TokenFilter.EnglishStemmer.Filter)
.UserDefined(TokenFilter.EnglishPossessiveStemmer.DisplayName, TokenFilter.EnglishPossessiveStemmer.Filter)
.UserDefined(TokenFilter.PatternFilter.DisplayName, TokenFilter.PatternFilter.Filter)
.UserDefined(TokenFilter.SynonymFilter.DisplayName, TokenFilter.SynonymFilter.Filter)
.UserDefined(TokenFilter.StripLeadingCharNoise.DisplayName, TokenFilter.StripLeadingCharNoise.Filter)
.UserDefined(TokenFilter.NumericSynonymFilter.DisplayName, TokenFilter.NumericSynonymFilter.Filter)
.UserDefined(TokenFilter.StemmerExclusionFilter.DisplayName, TokenFilter.StemmerExclusionFilter.Filter)
.UserDefined(TokenFilter.AsciiFoldingTokenFilter.DisplayName, TokenFilter.AsciiFoldingTokenFilter.Filter)
.UserDefined(TokenFilter.DashWordsSynonymFilter.DisplayName, TokenFilter.DashWordsSynonymFilter.Filter)
.UserDefined(TokenFilter.DashSplitTokenFilter.DisplayName, TokenFilter.DashSplitTokenFilter.Filter);
}

我想根据我发现的类似错误的答案找到并删除标准令牌过滤器,但我没有看到它在这里被使用。

如何排除故障并解决此问题?

方法RegisterAnalyzers进行了一次调用,导致了以下代码:

private static AnalyzerBase CustomDescriptionAnalyzer()
{
var customAnalyzer = new CustomAnalyzer();
customAnalyzer.CharFilter = new List<string>
{
CharacterFilter.HtmlStrip.DisplayName,
CharacterFilter.UniCodeFilter.DisplayName
};
customAnalyzer.Tokenizer = Tokenizer.DescriptionTokenizer.DisplayName;

customAnalyzer.Filter = new List<string>
{
TokenFilter.Standard.DisplayName, 
TokenFilter.Lowercase.DisplayName,
TokenFilter.StripLeadingCharNoise.DisplayName,  
TokenFilter.PatternFilter.DisplayName,
TokenFilter.StripLeadingCharNoise.DisplayName,
TokenFilter.NormalizeNumberSeparator.DisplayName, 

我从customerAnalyzer.Filter列表中删除了TokenFilter.Standard.DisplayName行,现在我没有得到错误Type: parse_exception Reason: "Invalid synonym rule at line 1" CausedBy: "Type: illegal_argument_exception Reason: "The [standard] token filter has been removed

参见

  • 7.0
  • [standard]令牌过滤器已被删除#175
  • 标准令牌过滤器删除导致升级后异常#50734

相关内容

  • 没有找到相关文章

最新更新