3
votes

I'm currently trying to configure an elasticsearch index in a .NET project (i'm new to ES).

We are using NEST 7.3.0

client.Indices.Create(lineItemIndex,
                c => c
                    .Settings(s => s
                    .Analysis(a => a
                        .Analyzers(aa => aa
                            .Custom("mynGram_analyzer",ca => ca
                            .Filters(new List<string> {"lowercase"})
                            .Tokenizer("mynGram")))
                        .TokenFilters(tf => tf
                            .NGram("mynGram", td => td
                                .MaxGram(15).MinGram(4)))))
                    .Map<ElasticSearchLineItem>(m => m
                        .Properties(ps => ps
                            .Text(ss => ss
                            .Name(na => na.LineItemName)
                            .Analyzer("mynGram")))
                        .Properties(ps => ps
                            .Keyword(kw => kw
                                .Name(na => na.LineItemId)))
                        .Properties(ps => ps
                            .Text(ss => ss
                            .Name(na => na.LineItemNumber)
                            .Analyzer("mynGram")))));

I'm getting the following error:

Type: illegal_argument_exception Reason: "The difference between max_gram and min_gram in NGram Tokenizer must be less than or equal to: 1 but was [11]. This limit can be set by changing the [index.max_ngram_diff] index level setting."

I understand what the issue is. But I can't figure out where to set this max_ngram_diff setting. I'm trying to look through the documentation.

But they use 3 for both min and max.

I've also found an example where they have the setting in the JSON, that gets send to ES, but I can't replicate it, in the c# code. I hope someone can help me.

1

1 Answers

8
votes

You can change this setting with following

var createIndexResponse = await client.Indices.CreateAsync("index_name",
    c => c.Settings(s => s.Setting(UpdatableIndexSettings.MaxNGramDiff, 11)));

Hope that helps.