一尘不染

C#Nest ElasticSearch无法将“ token_chars”映射到Nest fluentMapping

elasticsearch

我已经通过ElasticSearch Sense浏览器插件创建了以下索引,并且还创建了C#Nest
Fluent映射。我可以在nGrams过滤器上表达Nest中除“ token_chars”以外的所有内容。我没有在C#嵌套上获得强类型属性来添加“
token_chars”。有人遇到过同样的问题吗?

json和c#设置如下所示。请帮忙

        "analysis": {
           "analyzer": {
              "str_index_analyzer": {
                 "filter": [
                    "lowercase",
                    "substring"
                 ],
                 "tokenizer": "keyword"
              },
           "filter": {
              "substring": {
                 "max_gram": "50",
                 "type": "nGram",
                 "min_gram": "2",
                 "token_chars": [ /*Not able to map */
                    "letter",
                    "digit"
                 ]
              }
           }

我没有在C#嵌套上获得强类型属性来添加“ token_chars”。有人面临同样的问题吗?

           var result = this._client.CreateIndex("mkfindex1", c => c
           .Analysis(a => a.Analyzers(an => an.Add("str_index_analyzer", new CustomAnalyzer()
            {
                Filter = new string[] { "lowercase", "substring" },
                Tokenizer = "keyword"
            })).TokenFilters(bases => bases.Add("substring", new NgramTokenFilter()
            {
                MaxGram = 50,
                MinGram = 2,

                /*"token_chars": [//Not able to map
                    "letter",
                    "digit"
                 */
             }))));

阅读 284

收藏
2020-06-22

共1个答案

一尘不染

我遇到了同样的问题。解决方法是不使用Fluent Mapping,而仅通过Settings.Add()方法将您的分析设置直接指定为Fluent
Dictionary条目。下面是一个应正确配置索引的示例。

 var result = this._client.CreateIndex("mkfindex1", c => c
     .Settings.Add("analysis.analyzer", "str_index_analyzer")
     .Settings.add("analysis.analyzer.str_index_analyzer.type", "custom")
     .Settings.add("analysis.analyzer.str_index_analyzer.tokenizer", "keyword")
     .Settings.Add("analysis.analyzer.str_index_analyzer.filter.0", "lowercase")
     .Settings.Add("analysis.analyzer.str_index_analyzer.filter.1", "substring")
     .Settings.add("analysis.filter.substring.type", "nGram")
     .Settings.add("analysis.filter.substring.min_gram", "2")
     .Settings.add("analysis.filter.substring.max_gram", "50")
     .Settings.add("analysis.filter.substring.token_chars.0", "letter")
     .Settings.add("analysis.filter.substring.token_chars.0", "digit")
   );

希望这可以帮助。

2020-06-22