# How to use dynamic mapping with javascript client putmapping

**URL:** <https://discuss.elastic.co/t/how-to-use-dynamic-mapping-with-javascript-client-putmapping/32682>\
**Category:** Elasticsearch\
**Created:** [October 21, 2015, 3:13pm UTC](https://discuss.elastic.co/t/how-to-use-dynamic-mapping-with-javascript-client-putmapping/32682 "2015-10-21T15:13:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmarker1](https://avatars.discourse-cdn.com/v4/letter/b/e47774/32.png) [@bmarker1](https://discuss.elastic.co/u/bmarker1)\
**Post date:** [October 21, 2015, 3:13pm UTC](https://discuss.elastic.co/t/how-to-use-dynamic-mapping-with-javascript-client-putmapping/32682/1 "2015-10-21T15:13:06Z")

</div>

I can't seem to figure out how to use dynamic mapping using the javascript client. My goal is to convert everything into a string. I have tried multiple things, but the documentation lacks an example. I've read that it needs to be in a body, I've read I don't need the 'mappings' field if I'm using .putMapping (I've tried both). I get an error index not created if I try to map before the index goes through .create function. But when I create it, the mapping is already set, so I'm confused. This is one thing I have tried (I've tried before the create and outside of the create function): HELP please!

data:

event. has a bunch of other data

```
event.mappings = {
            "event": {
                "dynamic_templates": [
                    {
                      "en": {
                        "match": "*",
                        "mapping": {
                          "type": "string"
                        }
                      }
                    }
                ]
            }
        }

```

call:

```
 esClientLookup.getClient( function(esClient) {
            esClient.create({
                index: 'timeline-2015-10-24',
                type: 'event',
                body: event
            }, function (error, response) {
                if (error) {
                    logger.log(logger.SEVERITY.ERROR, 'acceptEvent elasticsearch create failed with: '+ error + " req:" + JSON.stringify(event));
                    res.status(500).send('Error saving document');
                } else {
                    esClient.indices.putMapping({index:'timeline-2015-10-24', type:'event', body:event});
                    res.status(200).send('Accepted');
                }
            });
        });
```

---

<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:** [July 5, 2017, 11:43pm UTC](https://discuss.elastic.co/t/how-to-use-dynamic-mapping-with-javascript-client-putmapping/32682/2 "2017-07-05T23:43:30Z")

</div>


