我正在尝试使用来自 C# 应用程序的 Nest 为电话号码创建自定义分析器。以下似乎没有做任何有用的事情:
var settings = new IndexSettings
{
NumberOfReplicas = maximumReplicas ?? _configuration.Value.Replicas,
NumberOfShards = _configuration.Value.Shards,
};
settings.Add("index.refresh_interval", "10s");
settings.Add("merge.policy.merge_factor", "10");
settings.Add("search.slowlog.threshold.fetch.warn", "1s");
const string phoneorcodePattern = @"([^\\p{L})"; // ignore that this is silly
settings.Analysis.Tokenizers.Add(new KeyValuePair<string, TokenizerBase>("phoneorpostcode", new PatternTokenizer() { Pattern = phoneorcodePattern, Flags = "CASE_INSENSITIVE" }));
settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("phoneorpostcode", new CustomAnalyzer() { Tokenizer = "phoneorpostcode", Filter = new List<string> { "lowercase" } }));
// standard analzers
settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("keyword", new KeywordAnalyzer()));
settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("simple", new SimpleAnalyzer()));
// field mapping stuff here...
client.CreateIndex(_searchConnection.Settings.SearchIndexName, settings);
当我使用 CURL 测试分析器时:
D:\>curl -XGET "http://localhost:9200/blah/_analyze?analyzer=phoneorpostcode&pretty" -d "123 456 789"
我得到:
{
"error" : "ElasticSearchIllegalArgumentException[failed to find analyzer [phoneorpostcode]]",
"status" : 400
}
问题:
1-为什么会出错?索引创建得很好,我有使用分析器的字段。
2-我怎样才能看到映射中的分析器?
(3-什么是好的正则表达式?我需要删除所有空格,这样我才能使用通配符查询。回答这个问题的奖励积分:)
干杯