Index template creation fails when multiple index patterns are provided due to invalid comma-separated pattern handling
Closed this issue · 2 comments
Elastic.Clients.Elasticsearch version:
8.17.4
Elasticsearch version:
8.17.4
.NET runtime version:
net8.0
Operating system version:
Windows 11 Enterprise 26100.6584
Description of the problem including expected versus actual behavior:
When creating an index template in Elasticsearch, I am passing multiple patterns to the IndexPattenrs property as an array (e.g., ["pattern-1-", "pattern-2"]). However, Elasticsearch treats these as a single string with a comma separating the patterns (e.g., "pattern-1-,pattern-2"), rather than as two distinct patterns. This results in a validation error and the index template does not get created because commas are not allowed in index names or patterns.
Steps to reproduce:
- Create an index template with more than one index pattern
var patternOne = "pattern-1-*";
var patternTwo = "pattern-2";
client.Indices.PutIndexTemplateAsync(indexTemplateName, it => it
.IndexPatterns(new[] { patternOne, patternTwo })
.Priority(priority)
.AllowAutoCreate(false)
.Template(t => t
.Settings(s => s
...
.Mappings(m => m
...
)
)
)
Expected behavior
The index template is created with two index patterns in the index patterns array.
Example Error
Invalid Elasticsearch response built from a unsuccessful (400) low level call on PUT: /_index_template/a6c72323-sample-89123-v1-template
Exception: Request failed to execute. Call: Status code 400 from: PUT /_index_template/a6c72323-sample-89123-v1-template. ServerError: Type: invalid_index_template_exception Reason: "index_template [a6c72323-sample-89123-v1-template] invalid, cause [Validation Failed: 1: index_pattern [a6c72323-sample-89123-v1-*,a6c72323-sample-89123-v1] must not contain a ',';2: index_pattern [a6c72323-sample-89123-v1-*,a6c72323-sample-89123-v1] must not contain the following characters ['/',',','|','>','?','*','<','"',' ','\'];]"
Hi @Botonomus9000 ,
this is fixed in more recent versions of the client. Depending on the complexity of your project I would recommend you to upgrade the client to the latest 8.18.x version and check if the problem persists. This should be the most straightforward approach.
If the problem persists, please upgrade the client to the latest 8.19.x version. 8.19 is the LTS branch that will be around for a long time. Please be aware that with 8.19 we backported tons of usability improvements and fixes from the 9.x branches which means that you will potentially also be affected by all the breaking changes listed here:
https://www.elastic.co/docs/release-notes/elasticsearch/clients/dotnet/breaking-changes#elasticsearch-net-client-900-breaking-changes
You don't have to worry much about using different client vs server versions since the clients are backwards compatible (see here).
Please let me know if that solves your problem.
Thank you @flobernd
If this is fixed in newer version then good to close. I'll see about updating the client.