C#Nest ElasticSearch无法映射"token_chars";嵌套fluentMapping [英] C# Nest ElasticSearch Not able to map "token_chars" to Nest fluentMapping

查看:199
本文介绍了C#Nest ElasticSearch无法映射"token_chars";嵌套fluentMapping的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created below index through ElasticSearch Sense browser plugin, and also created C# Nest Fluent Mapping. I can express everything in Nest except "token_chars" on nGrams filter. I am not getting strongly typed property on C# nest to add "token_chars". Has anybody faced the same problem?

json和c#设置如下所示. 请帮助

The json and c# settings are listed as below. Please help

        "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".有人遇到过同样的问题吗?

I am not getting strongly typed property on C# nest to add "token_chars". Is anybody faced the same problem?

           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"
                 */
             }))));

推荐答案

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

I have run into the same issue. The workaround for this is to not use the Fluent Mapping and just specify your analysis settings directly as Fluent Dictionary entries via the Settings.Add() method. Below is an example that should configure your index correctly.

 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")
   );

希望这会有所帮助.

这篇关于C#Nest ElasticSearch无法映射"token_chars";嵌套fluentMapping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆