You can use put_mapping API for this purpose.
In your case, the following should work.
client = Elasticsearch::Model.client
data = { "tweet" => { "properties" => { "user_name" => { "type" => "string" } } } }
client.indices.put_mapping(
{
index: 'twitter',
type: 'tweet',
body: data
})
source
share