# Python Elasticsearch : Index mapping inconsistencies between 'es.index' and 'es.indices.create'

**URL:** <https://discuss.elastic.co/t/python-elasticsearch-index-mapping-inconsistencies-between-es-index-and-es-indices-create/288584>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [November 8, 2021, 4:37am UTC](https://discuss.elastic.co/t/python-elasticsearch-index-mapping-inconsistencies-between-es-index-and-es-indices-create/288584 "2021-11-08T04:37:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![corndog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/corndog/32/96803_2.png) [@corndog](https://discuss.elastic.co/u/corndog)\
**Post date:** [November 8, 2021, 4:37am UTC](https://discuss.elastic.co/t/python-elasticsearch-index-mapping-inconsistencies-between-es-index-and-es-indices-create/288584/1 "2021-11-08T04:37:00Z")

</div>

I'm trying to implement a custom index mapping (my\_mapping) in Python, BUT, I do not get the expected index mapping after the python file is run!

```auto
file.py
----------
my_mapping = """
{
    "settings": {
        "number_of_shards": "1",
        "number_of_replicas": "1"
    },
    "mappings": {
        "properties": {
            "site": {
                "type": "completion",
            },
            "geometry": {
                "type": "geo_shape"
            }
        }
    }
}"""
result = es.index(index='my_index', document=my_mapping)

```

Expected Output:

```auto
{
  "mappings": {
    "_doc": {
      "properties": {
        "geometry": {
          "type": "geo_shape"
        },
        "site": {
          "type": "completion",
          "analyzer": "simple",
          "preserve_separators": true,
          "preserve_position_increments": true,
          "max_input_length": 200
        }
      }
    }
  }
}

```

Actual horrible output:

```auto
{
  "mappings": {
    "_doc": {
      "properties": {
        "mappings": {
          "properties": {
            "properties": {
              "properties": {
                "geometry": { ...........

```

BUT! NOTE that when I instead use the following python to create the index, I DO get the expected outcome.

```auto
result = es.indices.create(index='my_index', document=my_mapping)

```

Can someone please explain to me the inconsistency, and HOW to generate the expected outcome USING **es.index**

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 8, 2021, 6:59am UTC](https://discuss.elastic.co/t/python-elasticsearch-index-mapping-inconsistencies-between-es-index-and-es-indices-create/288584/2 "2021-11-08T06:59:35Z")

</div>

I think that `es.index` is meant to index documents. Not to call the create index API.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 8, 2021, 7:14am UTC](https://discuss.elastic.co/t/python-elasticsearch-index-mapping-inconsistencies-between-es-index-and-es-indices-create/288584/3 "2021-11-08T07:14:14Z")

</div>

@dadoonet is correct

`es.indices.create` - [API Documentation — Elasticsearch 7.15.1 documentation](https://elasticsearch-py.readthedocs.io/en/v7.15.1/api.html#elasticsearch.Elasticsearch.create)  
`es.index` - [API Documentation — Elasticsearch 7.15.1 documentation](https://elasticsearch-py.readthedocs.io/en/v7.15.1/api.html#elasticsearch.Elasticsearch.index)

---

<div class="post-metadata">

**Author:** ![corndog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/corndog/32/96803_2.png) [@corndog](https://discuss.elastic.co/u/corndog)\
**Post date:** [November 8, 2021, 8:29am UTC](https://discuss.elastic.co/t/python-elasticsearch-index-mapping-inconsistencies-between-es-index-and-es-indices-create/288584/4 "2021-11-08T08:29:58Z")

</div>

Thanks all for clarifying. I’ll stick to using es.indices.create

@warkolm - I forgot to mention but I also get a depreciation warning when using es.indices.create()

I’m not sure of how to rectify this

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 8, 2021, 9:11am UTC](https://discuss.elastic.co/t/python-elasticsearch-index-mapping-inconsistencies-between-es-index-and-es-indices-create/288584/5 "2021-11-08T09:11:14Z")

</div>

Ahh not sure on that, hopefully one of the clients team will drop by and comment 🙂

---

<div class="post-metadata">

**Author:** ![corndog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/corndog/32/96803_2.png) [@corndog](https://discuss.elastic.co/u/corndog)\
**Post date:** [November 9, 2021, 5:31am UTC](https://discuss.elastic.co/t/python-elasticsearch-index-mapping-inconsistencies-between-es-index-and-es-indices-create/288584/6 "2021-11-09T05:31:57Z")

</div>

@warkolm I can answer my own question now. To circumvent the deprecation warning I use the explicit "mappings" parameter as opposed to the more generic "body" parameter. Eg:

```auto
es.indices.create(index='my_index', mappings="my_mapping")

```

No more warnings!

---

<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 7, 2021, 5:32am UTC](https://discuss.elastic.co/t/python-elasticsearch-index-mapping-inconsistencies-between-es-index-and-es-indices-create/288584/7 "2021-12-07T05:32:23Z")

</div>

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