Im very unfamiliar with ElasticSearch, but basically I've been trying to figure out how to make all database fields that are string to be searchable case insensitively. As currently the Automap creates them with text fields and keyword textfields and the whole logic for searching is using keywords, and doesn't look like it is changeable, due to some business logic.
I am trying to understand how can I add a lowercase normalizer when all of the indexes are created and mapped. Here is the code as it is.
public void CheckIndexes(IServiceCollection services)
{
var sp = services.BuildServiceProvider();
var elastiClient = sp.GetService<ElasticSearchClient>();
var indexes = Indexes.List.Select(x => x.IndexName);
foreach (var index in Indexes.List)
{
if (!elastiClient.Client.Indices.Exists(index.IndexName).Exists)
{
elastiClient.
Client.
Indices.
Create(index.IndexName, x => x
.Settings(b => b
.NumberOfShards(1)
.NumberOfReplicas(0))
.Map<BaseEntity>(m=>m
.AutoMap(index.EntityType)));
}
}
}
}
I tried adding this, but then I am receiving an exception "{"Sequence contains no elements"}"
elastiClient
.Client
.Indices
.Create(index.IndexName, c => c
.Settings(s => s
.Analysis(a => a
.Normalizers(n => n
.Custom("lowercase", cn => cn
.Filters("lowercase")
)
)
)
)
.Map<BaseEntity>(m => m
.AutoMap(index.EntityType)
.Properties(p => p
.Text(t => t
.Name(n => n)
.Fields(f => f
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
.Keyword(k => k
.Name("keyword_lowercase")
.Normalizer("lowercase")
.IgnoreAbove(256)
)
)
)
)
)
);