user4636030
user4636030

Reputation:

Elastic search model gem (rails), add new field to mapping

Following is the API to update mapping of Elastic search

PUT twitter/_mapping/tweet 
{
 "properties": {
   "user_name": {
    "type": "string"
   }
  }
 }

This add a new field called user_name to the tweet mapping type. How to achieve this using elastic search model gem https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model

Upvotes: 7

Views: 2198

Answers (1)

Pragadeesh R
Pragadeesh R

Reputation: 166

You can use the put_mapping API for this purpose.

For 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 
})

Upvotes: 11

Related Questions