<p dir="auto">I am trying to make aggregations on time series to get fixed-duration buckets of time.<br>
I need to search based on timestamp (<code class="notranslate">ts</code> field) but never on values (<code class="notranslate">value</code> field) so my mapping specifies to skip indexing on <code class="notranslate">value</code>.<br>
However, when I aggregate, it seesms that ES does not find the <code class="notranslate">value</code> field and use count zero instead.</p>
<p dir="auto">To reproduce (marvel syntax):</p>
<ul dir="auto">
<li>define a mapping template as:</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PUT _template/test
{
  &quot;template&quot;: &quot;test&quot;,
  &quot;mappings&quot;: {
    &quot;metric&quot; : {
      &quot;properties&quot;: {
        &quot;ts&quot;: { &quot;type&quot;: &quot;date&quot;},
        &quot;value&quot;: { &quot;type&quot;: &quot;double&quot;, &quot;index&quot;: &quot;no&quot;}
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">PUT _template/test
{
  "template": "test",
  "mappings": {
    "metric" : {
      "properties": {
        "ts": { "type": "date"},
        "value": { "type": "double", "index": "no"}
      }
    }
  }
}
</code></pre></div>
<ul dir="auto">
<li>index one document:</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="POST test/metric
{
  &quot;ts&quot;: 4,
  &quot;value&quot;: 42
}"><pre class="notranslate"><code class="notranslate">POST test/metric
{
  "ts": 4,
  "value": 42
}
</code></pre></div>
<ul dir="auto">
<li>aggregate:</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="GET test/metric/_search?search_type=count
{
  &quot;aggs&quot;: {
    &quot;sum_indexed_field&quot;: { // non sense, only here to show aggregation work on indexed field
      &quot;sum&quot;: {
        &quot;field&quot; : &quot;ts&quot;
      }
    },
    &quot;sum_nonindexed_field&quot; : {
      &quot;sum&quot; : {
        &quot;field&quot;: &quot;value&quot;
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">GET test/metric/_search?search_type=count
{
  "aggs": {
    "sum_indexed_field": { // non sense, only here to show aggregation work on indexed field
      "sum": {
        "field" : "ts"
      }
    },
    "sum_nonindexed_field" : {
      "sum" : {
        "field": "value"
      }
    }
  }
}
</code></pre></div>
<p dir="auto">Ouput is rather disappointing:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
   &quot;took&quot;: 240,
   &quot;timed_out&quot;: false,
   &quot;_shards&quot;: {
      &quot;total&quot;: 4,
      &quot;successful&quot;: 4,
      &quot;failed&quot;: 0
   },
   &quot;hits&quot;: {
      &quot;total&quot;: 1,
      &quot;max_score&quot;: 0,
      &quot;hits&quot;: []
   },
   &quot;aggregations&quot;: {
      &quot;sum_indexed_field&quot;: {
         &quot;value&quot;: 4 // ok
      },
      &quot;sum_nonindexed_field&quot;: {
         &quot;value&quot;: 0 // should get 42 here
      }
   }
}"><pre class="notranslate"><code class="notranslate">{
   "took": 240,
   "timed_out": false,
   "_shards": {
      "total": 4,
      "successful": 4,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "sum_indexed_field": {
         "value": 4 // ok
      },
      "sum_nonindexed_field": {
         "value": 0 // should get 42 here
      }
   }
}
</code></pre></div>
<p dir="auto">Am I doing something wrong?<br>
Is this due to the way aggregations work?</p>
<p dir="auto">Note 1 : using <code class="notranslate">not_analyzed</code> instead of <code class="notranslate">no</code> makes it work.<br>
Note 2 : adding <code class="notranslate">"doc_values": true</code> makes it work as well.</p>
<p dir="auto">But I'd like to understand.</p>
<p dir="auto">I am using _source field in my sort script to sort docs based on complex logic involving multi level nested fields. But accessing _source from disk for each matched document is performing poorly, giving me ~ 3 sec response times.</p>
<p dir="auto">It would me very efficient to have a cache for this field, so that costly disk accesses can be avoided on every request. It would cost more memory, but would solve performance problem for many advanced sorting use cases.</p>