Product Engineer, CTO & a Beer Enthusiast
Experiments, thoughts and scripts documented for posterity.
Sep, 2014
As you probably know that mappings in elasticsearch cannot be changed, for example like changing a property type from a string to an int etc. The only way to make such changes is to copy the entire index into a brand new index with new mappings.
elasticdump --input=http://localhost:9200/assets_v1 --output=http://locahost:9200/assets_v2 --type=data --bulk=true --limit=500 --bulk-use-output-index-name=true
Now all that you need to do is to delete the alias from the original index and assign it the new index. This way the calling client using the alias for querying and indexing would have no impact
curl -XPOST 'http://localhost:9200/_aliases' -d '
{
"actions" : [
{ "remove" : { "index" : "assts_v1", "alias" : "assets" } },
{ "add" : { "index" : "assts_v2", "alias" : "assets" } }
]
}'
But what about the documents that were updated during the scan and scroll process? Well, that's tricky but if your model does have a update date property you can always re run the es dump to fetch only the documents that were updated after a certain date time.
elasticdump --input=http://localhost:9200/assets_v1 --output=http://locahost:9200/assets_v2 --type=data --bulk=true --limit=500 --bulk-use-output-index-name=true --searchBody='{"query":{"bool":{"must":[{"range":{"asset.submitDate":{"gte":"2014-09-01","lte":"2014-09-21"}}}]}}}'