Introduce a rescore window for script scores

The idea here is that if you query finds many thousands of results then
it isn't worth it to run expensive script scoring on all of them.  Instead
we run the script scoring on the top 8192 per shard.  If your query is a
"good" full text query then Lucene's default scoring algorithm will already
be pretty good and put the results you are probably looking for in the first
couple thousand any way so the script score will pick it up.

This is kind of difficult because Elasticsearch 0.90.X doesn't actually
support multiple rescore windows.  1.X will.  Instead we emulate it by just
using one rescore if there is just one required, and by adding the script
score to both the query and the rescore if there is already a rescore when
we go to add the script score.  We make some effort to not have a phrase
rescore unless we're pretty sure it'll be important so we end up falling
into the single rescore case quite frequently.  Frequently enough that we'd
catch all the queries that we currently see in the CirrusSearch-slow log file.
This change reduces their run times by a factor of 60 which I imagine will
reduce load as well.

Because prefix searches rely on being able to sort large numbers of result
quickly this moves most of them to a single sort.  Those that have default
templates boosted still have the 8192 window per shard which _should_
mostly be ok.

DEPLOYMENT: If this is deployed before incoming_redirect_links has been
full migrated to incoming_links then prefix sort order will change until
the migration is complete.  It won't break, but it'll change.

Change-Id: I6c4c197ca8994f4005ba2b2b536b9099a8c6236e
Merge "Introduce a rescore window for script scores"