Greetings
The variable_width_histogram works fine as the first aggregation
GET ntsp_dbas_bfg/_search
{
  "query": {
    "term": {
      "name": {
        "value": "Valsartanic acid"
      }
    }
  },
  "size": 0,
  "aggs": {
    "ms2": {
      "nested": {
        "path": "ms2"
      },
      "aggs": {
        "averaged": {
          "variable_width_histogram": {
            "field": "ms2.mz",
            "buckets": 8000
          },
          "aggs": {
            "bucket_filter": {
              "bucket_selector": {
                "buckets_path": {
                  "numBuckets": "_count"
                },
                "script": "params.numBuckets > 1"
              }
            }
          }
        }
      }
    }
  }
}
But if I use the sampler aggregation to limit the number of buckets to aggregate, I get an error.
GET ntsp_dbas_upb/_search
{
  "query": {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "filter_docs": {
      "sampler": {
        "shard_size": 100
      },
      "aggs": {
        "ms2": {
          "nested": {
            "path": "ms2"
          },
          "aggs": {
            "averaged": {
              "variable_width_histogram": {
                "field": "ms2.mz",
                "buckets": 8000
              },
              "aggs": {
                "bucket_filter": {
                  "bucket_selector": {
                    "buckets_path": {
                      "numBuckets": "_count"
                    },
                    "script": "params.numBuckets > 1"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
The error is:
"type": "illegal_argument_exception",
"reason": "[variable_width_histogram] cannot be nested inside an aggregation that collects more than a single bucket."
Is there an error in the way I am using the aggregation? Or maybe the variable_width_histogram is throwing an error when it doesn't need to?
Any advice or thoughts would be much appreciated
Best regards