I want to put a new mapping to a index without deleting the index. Elasticsearch::Model does not seem to provide an API for this. Or do I miss it?
3 Answers
1 Login to your elastic search client
require 'elasticsearch'
client = Elasticsearch::Client.new log: true
2 Create new index with mapping data
client.indices.create index: 'testindex', body: {
"mappings": {
"dynamic": false,
"properties": {
title: { type: 'text' }
}
}
}
3 checked your newly created index
client.indices.get_mapping index: "testindex"
Comments
You can PUT a new mapping over the old mapping without deleting any data or dropping the index. The catch is that updated field mappings only get applied to new data, not existing data. If you want the new mapping to be applied to old data then you need to re-index.
1 Comment
Roman
Indeed. I would have to reindex everything. My question was about how to change the mapping using the elasticsearch-ruby API.
Given the Elasticsearch client, you can update the existing field mappings like this:
client.indices.put_mapping index: 'myindex', type: 'mytype', body: {
mytype: {
properties: {
title: { type: 'string', analyzer: 'snowball' }
}
}
}