Hi there,
This is my first post here, so I apologise in advance if I'm not too clear or if my question has been asked already.
I have ElasticSearch running in a Docker cluster, I use it to search through a ASP.NET core API that queries ES.
I would like to define the index mappings for ES at cluster creation, running a job in my docker-compose that uses a .NET console app to put the requests on ES to define the mappings.
I have seen that using templates should do the job for me, but I can't find any examples for best practices in NEST or ElasticSearch-NET so I thought I'd ask here.
My idea would be to simply define a template that is applied to any new index that is created. Then I run an external job that seeds ES and any new index will have the same mapping applied to it whenever a new document needs to go in a new index.
I also want to define an alias that is common to all the new indexes.
The mappings I want to define are as below:
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"dynamic": false,
"properties": {
"Name": {
"type": "keyword"
},
"Cusip": {
"type": "keyword"
},
"ISIN": {
"type": "keyword"
},
"Ticker": {
"type": "keyword"
},
"suggest": {
"type": "completion",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}
And for the alias I need to use something like this:
{
"actions" : [
{ "add" : { "index" : "{index}", "alias" : "product" } }
]
}
How do I package it together into a template? Is using a template the right way to do this? How do I ensure that all new indexes have these settings?
Thanks in advance for your help
Simon