Python Client : Receive illegal_argument_exception error when trying to create an index template


I am trying to create an index template to use it for my data stream. I use this command to create the template:

es = client.Elasticsearch(['_host_name'], http_auth=('user', 'psw'), port=_port, scheme='https', timeout=60)
 ic = client.IndicesClient(es)
 tem_body = {
             "index_patterns": ["stesssss-*"],
             "data_stream": { },
             "composed_of": [],
             "priority": 500,
             "_meta": {
                 "description": "Template for datastream tes"
 response = ic.put_index_template('stesssss', tem_body)

When I run the code I get this error:

elasticsearch.exceptions.RequestError: RequestError(400, 'illegal_argument_exception', 'composable template [stesssss] template after composition is invalid')

and upper before the call stack I see this warning:
WARNING:Elasticsearch:PUT https://localhost:443/_index_template/stesssss [status:400 request:5.296s]

I've tried to look into the warning and I see this:

{"error":{"root_cause":[{"type":"resource_not_found_exception","reason":"index template matching [stesssss [status:400 request:5.296s] not found"}],"type":"resource_not_found_exception","reason":"index template matching [stesssss [status:400 request:5.296s] not found"},"status":404}

Could someone please help why I get this error? The roo_cause is more strange for me since obviously index template does not exist and I just want to create it! What am I doing wrong?


Perhaps you need to add the create flag see here

Creates or updates an index template.

Index templates | Elasticsearch Guide [7.14] | Elastic

Parameters: * name – The name of the template

  • body – The template definition
  • cause – User defined reason for creating/updating the index template
  • create – Whether the index template should only be added if new or can also replace an existing one
  • master_timeout – Specify timeout for connection to master

Hi Stephenb,
Thanks for your response. Create does not seem to be the solution. Generally the python API is very much vague to me! I have tried to use create but it tells me it is not defined! This is how I use it:

response = ic.put_index_template(name=template_name, body=tem_body, params=create)
NameError: name 'create' is not defined

My understanding from definition of create in the API ( * create – Whether the index template should only be added if new or can also replace an existing one) is that it is a boolean variable but when I try to use it as bool (below code) it gives me an other error:

create = True
 response = ic.put_index_template(template_name, tem_body, create)


  File ".../python3.9/site-packages/elasticsearch/client/", line 168, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
TypeError: put_index_template() got multiple values for argument 'params'

If you have an example of how to use the API, I very much appreciate it. I actually have tried different things but non of them work and I cannot think of anything else!



Apologies I am not a python programmer perhaps someone else can help.

I put Python in the Title perhaps someone will see it.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.