Variable_width_histogram cannot be nested in sampler

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

Greetings again,

the histogram aggregation works when nested inside a terms aggregation. So I've gotten around the problem that way. It seems as though variable_width_histogram throws a (for me) unexpected error when nested inside other aggregations.

GET ntsp_dbas*/_search
{
  "query": {
    "term": {
      "name": {
        "value": "Caprolactam"
      }
    }
  },
  "size": 0,
  "aggs": {
    "ms2": {
      "nested": {
        "path": "ms2"
      },
      "aggs": {
        "averaged": {
          "histogram": {
            "field": "ms2.mz",
            "interval": 0.015,
            "min_doc_count": 2
          },
          "aggs": {
            "avgmz": {
              "avg": {
                "field": "ms2.mz"
              }
            },
            "sumint": {
              "sum": {
                "field": "ms2.int"
              }
            }
          }
        }
      }
    }
  }
}