0

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?

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"
                 ]
              }
           }

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

1 Answer 1

5

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

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.