title: ES Scripted fields on large number of data
body: <p>I have a ES index with millions of records. Currently records are fetched using scroll api and are paginated. Also all fields are sortable.
  I have request for new additional fields (dependent on already existing fields). So wanted to use scripted fields.</p>
  <p>Can we apply scripted fields clubbed with scroll api and search_after api?</p>
  <p>Can we have scripted fields data sorted?</p>
  <p>Example:-
  We have a point collection system. Users have to collect certain points by doing some tasks in a certain time limit.</p>
  <pre><code>{
     user1: {
         &quot;endtime&quot;: &quot;1640807573000&quot;, // time epoch
         &quot;points&quot;: 100,
         &quot;target&quot;: 1000,
         ...
     },
     user2: {
         &quot;endtime&quot;: &quot;1640807573000&quot; // time epoch
         &quot;points&quot;: 200
         &quot;target&quot;: 5000,
         ...
     }, ... // millions of such records
  }
  </code></pre>
  <p>Values of <code>endtime</code>, <code>points</code>, <code>target</code> can be updated any time by other system.</p>
  <p>Admins can view the report of all users on a ES based paginated tabular UI or download the whole dump of tabular report in a csv format. Now, for the Admins, we want to have visibilty of following new parameters for every user in the report.</p>
  <ol>
  <li><code>Time left</code>: <code>(user.endtime - current time)</code> // Current Time is the time when report is fetched for realtime report.</li>
  <li><code>Expected work rate</code>: <code>( target - points ) / ( Time left )</code></li>
  <li><code>Zone</code>: On basis of Expected work rate ranges, classify in 3 zones; Red, Yellow, Green</li>
  </ol>
  <p>Also, these 3 new fields should have sorting, filtering and pagination.</p>
  <p>I wanted to calculate above 3 fields using scripted fields, when the report is fetched.</p>
  <p>Any suggestion on feasibility of above approach or recommendation for better approach?</p>