title: Elasticsearch - Bucket selector aggregation doesn't work - "must be declared inside of another aggregation"
body: <p>I fight with  this problem for few days. I want to filter records by aggregated data (sumA field). This is my request:</p>
  <pre><code>{
   &quot;size&quot;: 10000,
   &quot;aggs&quot;: {
   &quot;example_bucket_selector&quot;: {
    &quot;bucket_selector&quot;: {
      &quot;buckets_path&quot;: {
        &quot;sumA&quot;: &quot;sum_A&quot;
      },
      &quot;script&quot;: &quot;params.sumA &gt; 100&quot;
    }
  },
  &quot;sum_A&quot;: {
    &quot;sum&quot;: {
      &quot;field&quot;: &quot;A&quot;
    }
  },
  &quot;sum_B&quot;: {
    &quot;sum&quot;: {
      &quot;field&quot;: &quot;B&quot;
     }
    }
   }
  }
  </code></pre>
  <p>I'm getting this error:</p>
  <pre><code>  &quot;reason&quot;: &quot;Validation Failed: 1: bucket_selector aggregation [example_bucket_selector] must be declared inside of another aggregation;&quot;
  </code></pre>
  <p>What am I doing wrong?</p>