# Is it necessary to use putMapping() each time index() is called for a different type?

**URL:** <https://discuss.elastic.co/t/is-it-necessary-to-use-putmapping-each-time-index-is-called-for-a-different-type/95026>\
**Category:** Elasticsearch\
**Created:** [July 29, 2017, 12:27am UTC](https://discuss.elastic.co/t/is-it-necessary-to-use-putmapping-each-time-index-is-called-for-a-different-type/95026 "2017-07-29T00:27:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![full\_vlad](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@full\_vlad](https://discuss.elastic.co/u/full_vlad)\
**Post date:** [July 29, 2017, 12:27am UTC](https://discuss.elastic.co/t/is-it-necessary-to-use-putmapping-each-time-index-is-called-for-a-different-type/95026/1 "2017-07-29T00:27:40Z")

</div>

I am using the elasticsearch 5.2 node.js module.  
I know that _elasticsearch.index()_ creates the index if it's not already created. The problem, though, is that I am using a special mapping on one of the fields.  
For example if I'd recreate an index & type, I'd use something like this:

```
client.indices.putMapping({
    index: INDEX,
    type: TYPE,
    body: {
        properties: {
            field1: {
                type: 'string',
                analyzer: 'keyword'
            }
        }
    }
}

```

before I do all the indexes, so that the mapping is persistent in that _INDEX_ & _TYPE_.

What I want is, when I have a new _TYPE_, to use _elasticsearch.index()_ but don't want to have to use _elasticsearch.indices.putMapping()_ each time in order to guarantee that the desired mapping is consistent across all types inside that index.  
The question is:

> Is it necessary to use _elasticsearch.indices.putMapping()_ each time there's a new _TYPE_? And if so, what's the easiest way of propagating a certain _same_ mapping inside an index each time a new _TYPE_ is used?

Thanks a lot in advance!

---

<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:** [July 29, 2017, 1:10am UTC](https://discuss.elastic.co/t/is-it-necessary-to-use-putmapping-each-time-index-is-called-for-a-different-type/95026/2 "2017-07-29T01:10:58Z")

</div>

You have to know that in 6.0 having multiple types per index is not possible anymore.

If you want to apply the same logic everywhere you can think about using index templates but those are applied only for new indices.

---

<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:** [August 26, 2017, 1:10am UTC](https://discuss.elastic.co/t/is-it-necessary-to-use-putmapping-each-time-index-is-called-for-a-different-type/95026/3 "2017-08-26T01:10:59Z")

</div>

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