# Python Client : Receive illegal\_argument\_exception error when trying to create an index template

**URL:** <https://discuss.elastic.co/t/python-client-receive-illegal-argument-exception-error-when-trying-to-create-an-index-template/288457>\
**Category:** Elasticsearch\
**Created:** [November 4, 2021, 11:12pm UTC](https://discuss.elastic.co/t/python-client-receive-illegal-argument-exception-error-when-trying-to-create-an-index-template/288457 "2021-11-04T23:12:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MKH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mkh/32/100766_2.png) [@MKH](https://discuss.elastic.co/u/MKH)\
**Post date:** [November 4, 2021, 11:12pm UTC](https://discuss.elastic.co/t/python-client-receive-illegal-argument-exception-error-when-trying-to-create-an-index-template/288457/1 "2021-11-04T23:12:05Z")

</div>

Hi,

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

```auto

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](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?

Thanks

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [November 6, 2021, 1:41am UTC](https://discuss.elastic.co/t/python-client-receive-illegal-argument-exception-error-when-trying-to-create-an-index-template/288457/2 "2021-11-06T01:41:32Z")

</div>

Perhaps you need to add the `create` flag see [here](https://elasticsearch-py.readthedocs.io/en/v7.15.1/api.html#elasticsearch.client.IndicesClient.put_index_template)

> Creates or updates an index template.
> 
> [Index templates | Elasticsearch Guide [7.14] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.14/indices-templates.html)
> 
> 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

---

<div class="post-metadata">

**Author:** ![MKH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mkh/32/100766_2.png) [@MKH](https://discuss.elastic.co/u/MKH)\
**Post date:** [November 8, 2021, 5:27pm UTC](https://discuss.elastic.co/t/python-client-receive-illegal-argument-exception-error-when-trying-to-create-an-index-template/288457/3 "2021-11-08T17:27:53Z")

</div>

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:

```auto
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:

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

```

Error:

```auto
  File ".../python3.9/site-packages/elasticsearch/client/utils.py", 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!

Thanks,  
Maryam

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [November 8, 2021, 5:55pm UTC](https://discuss.elastic.co/t/python-client-receive-illegal-argument-exception-error-when-trying-to-create-an-index-template/288457/4 "2021-11-08T17:55:15Z")

</div>

@MKH

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

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 6, 2021, 5:55pm UTC](https://discuss.elastic.co/t/python-client-receive-illegal-argument-exception-error-when-trying-to-create-an-index-template/288457/5 "2021-12-06T17:55:55Z")

</div>

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