# Why does dynamic mapping not work for me?

**URL:** <https://discuss.elastic.co/t/why-does-dynamic-mapping-not-work-for-me/73414>\
**Category:** Elasticsearch\
**Created:** [January 31, 2017, 7:31pm UTC](https://discuss.elastic.co/t/why-does-dynamic-mapping-not-work-for-me/73414 "2017-01-31T19:31:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shira\_Bendor](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Shira\_Bendor](https://discuss.elastic.co/u/Shira_Bendor)\
**Post date:** [January 31, 2017, 7:31pm UTC](https://discuss.elastic.co/t/why-does-dynamic-mapping-not-work-for-me/73414/1 "2017-01-31T19:31:27Z")

</div>

Hi,  
I'm very new to Elasticsearch and I'm trying a simple test like this:

```
    TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));

    JsonObject event = Json.createObjectBuilder().add("d", 44).build();

    IndexResponse response = client.prepareIndex("myindex", "mytype").setSource(event).get();

```

I'm expecting the field "d" to be recognized as integer or long but it enters as text:

```
{
"myindex": {
"aliases": {},
"mappings": {
"mytype": {
"properties": {
"d": {
**"type": "text",**"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
},
"settings": {
"index": {
"creation_date": "1485890042953",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "vZpTJhDfREC7viQvESQFKQ",
"version": {
"created": "5000099"
},
"provided_name": "myindex"
}
}
}
}

```

if I'm adding the same object from the command line using curl it does enter as long. So what is the problem with this simple code?

Thanks

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [January 31, 2017, 7:52pm UTC](https://discuss.elastic.co/t/why-does-dynamic-mapping-not-work-for-me/73414/2 "2017-01-31T19:52:26Z")

</div>

I'm not familiar with `JsonObject`. Could you post the source that it generates? I'm not sure which override of `setSource` you are getting. There is an `Object...` override but I don't think it'd do the right thing for `JsonObject`.

---

<div class="post-metadata">

**Author:** ![Shira\_Bendor](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Shira\_Bendor](https://discuss.elastic.co/u/Shira_Bendor)\
**Post date:** [February 1, 2017, 8:18pm UTC](https://discuss.elastic.co/t/why-does-dynamic-mapping-not-work-for-me/73414/3 "2017-02-01T20:18:35Z")

</div>

JsonObject is javax.json.JsonObject.

The source that is generated is

{"d":44}

It looks like I'm getting to a writer that's not recognized and then the default is to make it a string.  
I'm thinking to write a method to "unwrap" the json and return it to the actual type but is this really necessary?

---

<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:** [March 1, 2017, 8:18pm UTC](https://discuss.elastic.co/t/why-does-dynamic-mapping-not-work-for-me/73414/4 "2017-03-01T20:18:38Z")

</div>

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