There should probably be a method in reindex all documents from one index into a new index. This is needed when one wants to change the mapping with no downtime. See http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/
Several other client libraries already include that functionality:
Early draft. For some reason I get a Java exception inside elastic search as soon as there are documents in the old index.
MapperParsingException[mapping [product]]; nested: ClassCastException[java.
util.ArrayList cannot be cast to java.util.Map];
The method is missing arguments to optionally overwrite the mapping and settings for the new index. Otherwise it would just be a copy.
* @return string The new index name
* @see http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/
public function reindex()
$scrollResponse = $this->request('_search', Request::GET,
array('query' => array(
'match_all' => array()
array('search_type' => 'scan', 'scroll' => '10m', 'size' => '100')
$scrollId = $scrollResponse->getScrollId();
$mapping = $this->getMapping();
$settings = $this->getSettings()->get();
$config = array();
$config['mappings'] = $mapping[$this->_name];
$config['settings'] = $settings;
$this->_name = $this->_name . date('-Y-m-d-Gis');
unset($mapping, $settings, $config);
$scrollResponse = $this->getClient()->request('_search/scroll', Request::GET,
array('scroll' => '10m', 'scroll_id' => $scrollId)
My suggestion is that this is something that should go into Elastica\Util as it is not directly an "index" function that can be called in Elasticsearch but a specific implementation. You pass the old and new index name and the magic is going to happen. What do you think?
@Tobion, did you complete your function to provide reindex functionality to Elastica?
I am looking at possibly doing the same thing, but came across your post and wondered if you had got any further with it?
@russellseymour As far as I know it is not in Elastica yet. So it would be very nice if you could pick it up.
@Tobion Any updates?
We just added reindexing at work using scan and scroll, I'll spend some time to extract it into Elastica\Util and make a pull request :)
@michellesanver Looking forward to it.
Added in #853