title: Calculate change rate of Time Series values
body: <p>I have an application which writes Time Series data to Elasticsearch. The (simplified) data looks like the following:</p>
  
  <pre><code>{
      "timestamp": 1425369600000,
      "shares": 12271
  },
  {
      "timestamp": 1425370200000,
      "shares": 12575
  },
  {
      "timestamp": 1425370800000,
      "shares": 12725
  },
  ...
  </code></pre>
  
  <p>I now would like to use an aggregation to calculate the change rate of the <code>shares</code> field by time "buckets", for example like</p>
  
  <p>The change rate of the share values within the last 10 minute "bucket" could be IMHO calculated as</p>
  
  <pre><code># of shares t1
  --------------
  # of shares t0
  </code></pre>
  
  <p>I tried the Date Histogram aggregation, but I guess that's not what I need to calculate the change rates, because this would only give me the <code>doc_count</code>, and it's not clear to me how I could calculate the change rate from these:</p>
  
  <pre><code>{
      "aggs" : {
          "shares_over_time" : {
              "date_histogram" : {
                  "field" : "timestamp",
                  "interval" : "10m"
              }
          }
      }
  }
  </code></pre>
  
  <p>Is there a way to achieve my goal with aggregations within Elasticsearch? I search the docs, but didn't find a matching method.</p>
  
  <p>Thanks a lot for any help!</p>