Indexing from a query with script

The reindex API does that basically.