0
votes

I find the way to create Nest elasticSearch client which contains default index with my custom analyzer. I know that I can create the client with default index and type name. I looks like this:

ElasticClient client = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200"))
                                                                      .DefaultIndex("my_index_name")
                                                                      .DefaultTypeNameInferrer(type => "my_type_name"));

But I don't know how to assign custom analyzer to default index at the same time. Is it possible?

1

1 Answers

1
votes

Setting

.DefaultIndex("my_index_name")

only tells the client the name of the index to use if no index has been specified on the request, and no index has been specified for a given POCO type T. It's important to note that it doesn't create an index.

Analyzers can be added when creating an index

client.CreateIndex("index-name", c => c
    .Settings(s => s
        .Analysis(a => a
            // add new Analyzers, Tokenizers, CharFilters, TokenFilters
        )
    )
);

or by updating an existing index

client.UpdateIndexSettings("index-name", u => u
    .IndexSettings(i => i
        .Analysis(a => a
            // add new Analyzers, Tokenizers, CharFilters, TokenFilters
        )
    )
);