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

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!

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.

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