# Specify Mappings while creating index using python client

**URL:** <https://discuss.elastic.co/t/specify-mappings-while-creating-index-using-python-client/292433>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [December 20, 2021, 7:22am UTC](https://discuss.elastic.co/t/specify-mappings-while-creating-index-using-python-client/292433 "2021-12-20T07:22:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunny3794.ad](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@sunny3794.ad](https://discuss.elastic.co/u/sunny3794.ad)\
**Post date:** [December 20, 2021, 7:22am UTC](https://discuss.elastic.co/t/specify-mappings-while-creating-index-using-python-client/292433/1 "2021-12-20T07:22:52Z")

</div>

As far as I know, Elasticsearch by default takes in data and stores it as string (except for date). So, I have been using the body parameter in the create function of the Elasticsearch python client to specify the field mappings. But it results in a deprecated warning. I have been trying to find an alternative to the body parameter but couldn't find anything. Is there any other way of passing the mappings to the create function?

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [December 20, 2021, 1:38pm UTC](https://discuss.elastic.co/t/specify-mappings-while-creating-index-using-python-client/292433/2 "2021-12-20T13:38:59Z")

</div>

"Create" with body worked fine for me. Sharing problematic code may be recommended for future question 🙂

[https://elasticsearch-py.readthedocs.io/en/v7.16.2/api.html#indices](https://elasticsearch-py.readthedocs.io/en/v7.16.2/api.html#indices)

```auto
index='new_index'
body = {
            "settings": {...},
            "mappings": {...}
        }
es.indices.create(index, body)

```

---

<div class="post-metadata">

**Author:** ![sunny3794.ad](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@sunny3794.ad](https://discuss.elastic.co/u/sunny3794.ad)\
**Post date:** [January 11, 2022, 8:41am UTC](https://discuss.elastic.co/t/specify-mappings-while-creating-index-using-python-client/292433/3 "2022-01-11T08:41:54Z")

</div>

Thank you! Just so you know the body parameter will be removed in future versions. I found the solution to this. You can pass the settings and mappings as separate arguments in the create function as follow:

index = 'new\_index'  
settings = {}  
mappings = {}  
es.indices.create(index=index, settings=settings, mappings=mappings)

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [January 11, 2022, 10:18am UTC](https://discuss.elastic.co/t/specify-mappings-while-creating-index-using-python-client/292433/4 "2022-01-11T10:18:09Z")

</div>

Thank you for sharing the solution!

---

<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:** [February 8, 2022, 10:18am UTC](https://discuss.elastic.co/t/specify-mappings-while-creating-index-using-python-client/292433/5 "2022-02-08T10:18:59Z")

</div>

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