简体   繁体   中英

Nest update index settings

I am following the post Creating an index Nest and trying to update my index settings. All runs fine however the html_strip filter is not stripping HTML. My code is

var node = new Uri(_url + ":" + _port);
var settings = new ConnectionSettings(node);
settings.SetDefaultIndex(index);
_client = new ElasticClient(settings);

//to apply filters during indexing use folding to remove diacritics and html strip to remove html
_client.UpdateSettings(
        f = > f.Analysis(descriptor = > descriptor
                .Analyzers(
                        bases = > bases
                        .Add("folded_word", new CustomAnalyzer
                        {
                        Filter = new List < string > { "icu_folding", "trim" },
                                Tokenizer = "standard"
                        }
                        )
                        )
                .CharFilters(
                        cf = > cf.Add("html_strip", new HtmlStripCharFilter())
                        )
                )
        );      

You are getting error:

Can't update non dynamic settings[[index.analysis.analyzer.folded_word.filter.0, index.analysis.char_filter.html_strip.type, index.analysis.analyzer.folded_word.filter.1, index.analysis.analyzer.folded_word.type, index.analysis.analyzer.folded_word.tokenizer]] for open indices[[my_index]]

Before you will try to update settings, close index first, update settings and reopen afterwards. Have a look.

client.CloseIndex(..);

client.UpdateSettings(..);

client.OpenIndex(..);

UPDATE

Add html_strip char filter to you custom analyzer:

.Analysis(descriptor => descriptor
                    .Analyzers(bases => bases.Add("folded_word",
                        new CustomAnalyzer
                        {
                            Filter = new List<string> { "icu_folding", "trim" }, 
                            Tokenizer = "standard", 
                            CharFilter = new List<string> { "html_strip" }
                        }))
                )

Now you can run test to check if this analyzer returns correct tokens:

client.Analyze(a => a.Index(indexName).Text("this <a> is a test <div>").Analyzer("folded_word"));

Output:

this
is
a
test

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM