Why does dynamic mapping not work for me?

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

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.

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?

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