<p dir="auto">The <a href="https://www.elastic.co/guide/en/elasticsearch/reference/2.1/search-aggregations-bucket-range-aggregation.html" rel="nofollow">range aggregation</a> currently based upon documentation and my testing only supports <code class="notranslate">to</code> and <code class="notranslate">from</code> terminology.</p>
<p dir="auto">In the theme to avoid ambiguity and prefer <code class="notranslate">lt</code>, <code class="notranslate">lte</code>, <code class="notranslate">gt</code>, and <code class="notranslate">gte</code> it would be nice if the aggregation query DSL support this.</p>
<p dir="auto">Current</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
    &quot;aggs&quot; : {
        &quot;price_ranges&quot; : {
            &quot;range&quot; : {
                &quot;field&quot; : &quot;price&quot;,
                &quot;ranges&quot; : [
                    { &quot;to&quot; : 50 },
                    { &quot;from&quot; : 50, &quot;to&quot; : 100 },
                    { &quot;from&quot; : 100 }
                ]
            }
        }
    }
}"><pre class="notranslate"><code class="notranslate">{
    "aggs" : {
        "price_ranges" : {
            "range" : {
                "field" : "price",
                "ranges" : [
                    { "to" : 50 },
                    { "from" : 50, "to" : 100 },
                    { "from" : 100 }
                ]
            }
        }
    }
}
</code></pre></div>
<p dir="auto">Proposed</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
    &quot;aggs&quot; : {
        &quot;price_ranges&quot; : {
            &quot;range&quot; : {
                &quot;field&quot; : &quot;price&quot;,
                &quot;ranges&quot; : [
                    { &quot;lte&quot; : 50 },
                    { &quot;gte&quot; : 50, &quot;lt&quot; : 100 },
                    { &quot;gte&quot; : 100 }
                ]
            }
        }
    }
}"><pre class="notranslate"><code class="notranslate">{
    "aggs" : {
        "price_ranges" : {
            "range" : {
                "field" : "price",
                "ranges" : [
                    { "lte" : 50 },
                    { "gte" : 50, "lt" : 100 },
                    { "gte" : 100 }
                ]
            }
        }
    }
}
</code></pre></div>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/dakrone/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/dakrone">@dakrone</a></p>
<p dir="auto">Currently, the behaviour appears to be that when specifying a range aggregation, the lower value is included, but the upper value is not.</p>
<p dir="auto">If I index the following data:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{ &quot;integer&quot; : 0,  &quot;float&quot; : 1.0, &quot;date&quot; : &quot;2014-03-10&quot; }
{ &quot;integer&quot; : 1,  &quot;float&quot; : 1.1, &quot;date&quot; : &quot;2014-03-11&quot; }
{ &quot;integer&quot; : 2,  &quot;float&quot; : 1.2, &quot;date&quot; : &quot;2014-03-12&quot; }
{ &quot;integer&quot; : 3,  &quot;float&quot; : 1.3, &quot;date&quot; : &quot;2014-03-13&quot; }
{ &quot;integer&quot; : 4,  &quot;float&quot; : 1.4, &quot;date&quot; : &quot;2014-03-14&quot; }
{ &quot;integer&quot; : 5,  &quot;float&quot; : 1.5, &quot;date&quot; : &quot;2014-03-15&quot; }
{ &quot;integer&quot; : 6,  &quot;float&quot; : 1.6, &quot;date&quot; : &quot;2014-03-16&quot; }
{ &quot;integer&quot; : 7,  &quot;float&quot; : 1.7, &quot;date&quot; : &quot;2014-03-17&quot; }
{ &quot;integer&quot; : 8,  &quot;float&quot; : 1.8, &quot;date&quot; : &quot;2014-03-18&quot; }
{ &quot;integer&quot; : 9,  &quot;float&quot; : 1.9, &quot;date&quot; : &quot;2014-03-19&quot; }
{ &quot;integer&quot; : 10, &quot;float&quot; : 2.0, &quot;date&quot; : &quot;2014-03-20&quot; }"><pre class="notranslate"><span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">0</span><span class="pl-kos">,</span>  <span class="pl-s">"float"</span> : <span class="pl-c1">1.0</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-10"</span> <span class="pl-kos">}</span>
<span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">1</span><span class="pl-kos">,</span>  <span class="pl-s">"float"</span> : <span class="pl-c1">1.1</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-11"</span> <span class="pl-kos">}</span>
<span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">2</span><span class="pl-kos">,</span>  <span class="pl-s">"float"</span> : <span class="pl-c1">1.2</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-12"</span> <span class="pl-kos">}</span>
<span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">3</span><span class="pl-kos">,</span>  <span class="pl-s">"float"</span> : <span class="pl-c1">1.3</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-13"</span> <span class="pl-kos">}</span>
<span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">4</span><span class="pl-kos">,</span>  <span class="pl-s">"float"</span> : <span class="pl-c1">1.4</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-14"</span> <span class="pl-kos">}</span>
<span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">5</span><span class="pl-kos">,</span>  <span class="pl-s">"float"</span> : <span class="pl-c1">1.5</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-15"</span> <span class="pl-kos">}</span>
<span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">6</span><span class="pl-kos">,</span>  <span class="pl-s">"float"</span> : <span class="pl-c1">1.6</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-16"</span> <span class="pl-kos">}</span>
<span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">7</span><span class="pl-kos">,</span>  <span class="pl-s">"float"</span> : <span class="pl-c1">1.7</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-17"</span> <span class="pl-kos">}</span>
<span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">8</span><span class="pl-kos">,</span>  <span class="pl-s">"float"</span> : <span class="pl-c1">1.8</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-18"</span> <span class="pl-kos">}</span>
<span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">9</span><span class="pl-kos">,</span>  <span class="pl-s">"float"</span> : <span class="pl-c1">1.9</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-19"</span> <span class="pl-kos">}</span>
<span class="pl-kos">{</span> <span class="pl-s">"integer"</span> : <span class="pl-c1">10</span><span class="pl-kos">,</span> <span class="pl-s">"float"</span> : <span class="pl-c1">2.0</span><span class="pl-kos">,</span> <span class="pl-s">"date"</span> : <span class="pl-s">"2014-03-20"</span> <span class="pl-kos">}</span></pre></div>
<p dir="auto">And then (illustrating with dates) do a range aggregation:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;date_range&quot; : {
  &quot;date_range&quot; : {
    &quot;field&quot; : &quot;date&quot;,
    &quot;ranges&quot; : [ {
      &quot;from&quot; : &quot;2014-03-15&quot;,
      &quot;to&quot; : &quot;2014-03-17&quot;
    } ]
  }
}"><pre class="notranslate"><span class="pl-s">"date_range"</span> : <span class="pl-kos">{</span>
  <span class="pl-s">"date_range"</span> : <span class="pl-kos">{</span>
    <span class="pl-s">"field"</span> : <span class="pl-s">"date"</span><span class="pl-kos">,</span>
    <span class="pl-s">"ranges"</span> : <span class="pl-kos">[</span> <span class="pl-kos">{</span>
      <span class="pl-s">"from"</span> : <span class="pl-s">"2014-03-15"</span><span class="pl-kos">,</span>
      <span class="pl-s">"to"</span> : <span class="pl-s">"2014-03-17"</span>
    <span class="pl-kos">}</span> <span class="pl-kos">]</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">I get the following results:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;date_range&quot; : {
  &quot;buckets&quot; : [ {
    &quot;key&quot; : &quot;2014-03-15T00:00:00.000Z-2014-03-17T00:00:00.000Z&quot;,
    &quot;from&quot; : 1.3948416E12,
    &quot;from_as_string&quot; : &quot;2014-03-15T00:00:00.000Z&quot;,
    &quot;to&quot; : 1.3950144E12,
    &quot;to_as_string&quot; : &quot;2014-03-17T00:00:00.000Z&quot;,
    &quot;doc_count&quot; : 2
  } ]
}"><pre class="notranslate"><span class="pl-s">"date_range"</span> : <span class="pl-kos">{</span>
  <span class="pl-s">"buckets"</span> : <span class="pl-kos">[</span> <span class="pl-kos">{</span>
    <span class="pl-s">"key"</span> : <span class="pl-s">"2014-03-15T00:00:00.000Z-2014-03-17T00:00:00.000Z"</span><span class="pl-kos">,</span>
    <span class="pl-s">"from"</span> : <span class="pl-c1">1.3948416E12</span><span class="pl-kos">,</span>
    <span class="pl-s">"from_as_string"</span> : <span class="pl-s">"2014-03-15T00:00:00.000Z"</span><span class="pl-kos">,</span>
    <span class="pl-s">"to"</span> : <span class="pl-c1">1.3950144E12</span><span class="pl-kos">,</span>
    <span class="pl-s">"to_as_string"</span> : <span class="pl-s">"2014-03-17T00:00:00.000Z"</span><span class="pl-kos">,</span>
    <span class="pl-s">"doc_count"</span> : <span class="pl-c1">2</span>
  <span class="pl-kos">}</span> <span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Here we can see that its not including both from and to in the aggregation (or otherwise we would expect a doc_count of 3. The same is true if you do a range aggregation on the integer or decimal number.</p>
<p dir="auto">Doing a different aggregation illustrates that its the upper thats getting omited:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;date_range_upper&quot; : {
  &quot;date_range&quot; : {
    &quot;field&quot; : &quot;date&quot;,
    &quot;ranges&quot; : [ {
      &quot;from&quot; : &quot;2014-03-01&quot;,
      &quot;to&quot; : &quot;2014-03-10&quot;
    } ]
  }
}"><pre class="notranslate"><span class="pl-s">"date_range_upper"</span> : <span class="pl-kos">{</span>
  <span class="pl-s">"date_range"</span> : <span class="pl-kos">{</span>
    <span class="pl-s">"field"</span> : <span class="pl-s">"date"</span><span class="pl-kos">,</span>
    <span class="pl-s">"ranges"</span> : <span class="pl-kos">[</span> <span class="pl-kos">{</span>
      <span class="pl-s">"from"</span> : <span class="pl-s">"2014-03-01"</span><span class="pl-kos">,</span>
      <span class="pl-s">"to"</span> : <span class="pl-s">"2014-03-10"</span>
    <span class="pl-kos">}</span> <span class="pl-kos">]</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Gives results</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;date_range_upper&quot; : {
  &quot;buckets&quot; : [ {
    &quot;key&quot; : &quot;2014-03-01T00:00:00.000Z-2014-03-10T00:00:00.000Z&quot;,
    &quot;from&quot; : 1.393632E12,
    &quot;from_as_string&quot; : &quot;2014-03-01T00:00:00.000Z&quot;,
    &quot;to&quot; : 1.3944096E12,
    &quot;to_as_string&quot; : &quot;2014-03-10T00:00:00.000Z&quot;,
    &quot;doc_count&quot; : 0
  } ]
}"><pre class="notranslate"><span class="pl-s">"date_range_upper"</span> : <span class="pl-kos">{</span>
  <span class="pl-s">"buckets"</span> : <span class="pl-kos">[</span> <span class="pl-kos">{</span>
    <span class="pl-s">"key"</span> : <span class="pl-s">"2014-03-01T00:00:00.000Z-2014-03-10T00:00:00.000Z"</span><span class="pl-kos">,</span>
    <span class="pl-s">"from"</span> : <span class="pl-c1">1.393632E12</span><span class="pl-kos">,</span>
    <span class="pl-s">"from_as_string"</span> : <span class="pl-s">"2014-03-01T00:00:00.000Z"</span><span class="pl-kos">,</span>
    <span class="pl-s">"to"</span> : <span class="pl-c1">1.3944096E12</span><span class="pl-kos">,</span>
    <span class="pl-s">"to_as_string"</span> : <span class="pl-s">"2014-03-10T00:00:00.000Z"</span><span class="pl-kos">,</span>
    <span class="pl-s">"doc_count"</span> : <span class="pl-c1">0</span>
  <span class="pl-kos">}</span> <span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">It needs to be possible to include the upper (or omit the lower) value in the aggregation specification.</p>
<p dir="auto">Here is an example of what I need to do:<br>
I want to do an aggregation as follows:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;aggregations&quot;: {
    &quot;intentDate&quot;: {
        &quot;date_range&quot;: {
            &quot;field&quot;: &quot;intentDate&quot;,
            &quot;ranges&quot;: [
                {
                    &quot;key&quot;: &quot;Overdue&quot;,
                    &quot;to&quot;: &quot;2014-02-17&quot;
                },
                {
                    &quot;key&quot;: &quot;March&quot;,
                    &quot;from&quot;: &quot;2014-02-18&quot;,
                    &quot;to&quot;: &quot;2014-03-17&quot;
                },
                {
                    &quot;key&quot;: &quot;April&quot;,
                    &quot;from&quot;: &quot;2014-03-18&quot;,
                    &quot;to&quot;: &quot;2014-04-15&quot;
                }
            ]
        }
    }
}"><pre class="notranslate"><span class="pl-s">"aggregations"</span>: <span class="pl-kos">{</span>
    <span class="pl-s">"intentDate"</span>: <span class="pl-kos">{</span>
        <span class="pl-s">"date_range"</span>: <span class="pl-kos">{</span>
            <span class="pl-s">"field"</span>: <span class="pl-s">"intentDate"</span><span class="pl-kos">,</span>
            <span class="pl-s">"ranges"</span>: <span class="pl-kos">[</span>
                <span class="pl-kos">{</span>
                    <span class="pl-s">"key"</span>: <span class="pl-s">"Overdue"</span><span class="pl-kos">,</span>
                    <span class="pl-s">"to"</span>: <span class="pl-s">"2014-02-17"</span>
                <span class="pl-kos">}</span><span class="pl-kos">,</span>
                <span class="pl-kos">{</span>
                    <span class="pl-s">"key"</span>: <span class="pl-s">"March"</span><span class="pl-kos">,</span>
                    <span class="pl-s">"from"</span>: <span class="pl-s">"2014-02-18"</span><span class="pl-kos">,</span>
                    <span class="pl-s">"to"</span>: <span class="pl-s">"2014-03-17"</span>
                <span class="pl-kos">}</span><span class="pl-kos">,</span>
                <span class="pl-kos">{</span>
                    <span class="pl-s">"key"</span>: <span class="pl-s">"April"</span><span class="pl-kos">,</span>
                    <span class="pl-s">"from"</span>: <span class="pl-s">"2014-03-18"</span><span class="pl-kos">,</span>
                    <span class="pl-s">"to"</span>: <span class="pl-s">"2014-04-15"</span>
                <span class="pl-kos">}</span>
            <span class="pl-kos">]</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">I want the upper value to be inclusive in the range.<br>
Then I want to take the results to create a filter - without having to do any date/datetime manipulation to translate between them.</p>