### Elasticsearch Version

main

### Installed Plugins

_No response_

### Java Version

_bundled_

### OS Version

All

### Problem Description

When downsampling an index we distinguish the following: dimensions, metrics and labels.

Dimensions and labels are identified explicitly in the mapping using `time_series_dimension` and `time_series_metric`. Every other field which is not explicitly identified as a dimension or a metric is implicitly identified as a label.
Right now `histogram` fields are still not supported as a metric type and we expect histograms to be treated as labels. This means that given a field whose type is `histogram` we expect at downsampling time that the latest value is propagated, as we do for any other label. This is not the case at the moment. Trying to downsample an index that includes a histogram label result in the following stack trace.

```
1>         "type" : "exception",
  1>         "reason" : "Unable to rollup index [test-histogram]",
  1>         "caused_by" : {
  1>           "type" : "exception",
  1>           "reason" : "[test-histogram/yqV5MKzoR-6vgUOrBMLgKQ][[test-histogram][0]] org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException:",
  1>           "caused_by" : {
  1>             "type" : "unsupported_operation_exception",
  1>             "reason" : "String representation of doc values for [histogram] fields is not supported",
  1>             "stack_trace" : "java.lang.UnsupportedOperationException: String representation of doc values for [histogram] fields is not supported
  1>    at org.elasticsearch.xpack.analytics.mapper.HistogramFieldMapper$HistogramFieldType$1$1.getBytesValues(HistogramFieldMapper.java:201)
  1>    at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.index.fielddata.LeafFieldData.getFormattedValues(LeafFieldData.java:38)
  1>    at org.elasticsearch.xpack.downsample.FieldValueFetcher.getLeaf(FieldValueFetcher.java:48)
  1>    at org.elasticsearch.xpack.downsample.RollupShardIndexer$TimeSeriesBucketCollector.lambda$getLeafCollector$0(RollupShardIndexer.java:267)
  1>    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
  1>    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
  1>    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
  1>    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
  1>    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575)
  1>    at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
  1>    at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616)
  1>    at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622)
  1>    at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627)
  1>    at org.elasticsearch.xpack.downsample.RollupShardIndexer$TimeSeriesBucketCollector.getLeafCollector(RollupShardIndexer.java:268)
  1>    at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.aggregations.support.TimeSeriesIndexSearcher$LeafWalker.<init>(TimeSeriesIndexSearcher.java:187)
  1>    at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.search.aggregations.support.TimeSeriesIndexSearcher.search(TimeSeriesIndexSearcher.java:79)
  1>    at org.elasticsearch.xpack.downsample.RollupShardIndexer.execute(RollupShardIndexer.java:148)
  1>    at org.elasticsearch.xpack.downsample.TransportRollupIndexerAction.shardOperation(TransportRollupIndexerAction.java:139)
  1>    at org.elasticsearch.xpack.downsample.TransportRollupIndexerAction.shardOperation(TransportRollupIndexerAction.java:45)
  1>    at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.support.broadcast.TransportBroadcastAction.lambda$asyncShardOperation$0(TransportBroadcastAction.java:298)
  1>    at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:50)
  1>    at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$2.accept(ActionRunnable.java:47)
  1>    at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.action.ActionRunnable$3.doRun(ActionRunnable.java:72)
  1>    at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:958)
  1>    at org.elasticsearch.server@8.7.0-SNAPSHOT/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
  1>    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
  1>    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
  1>    at java.base/java.lang.Thread.run(Thread.java:1589)
```

### Steps to Reproduce

Here is a YAML test that reproduces the issue.

```
setup:
  - skip:
      version: " - 8.4.99"
      reason: "rollup renamed to downsample in 8.5.0"

  - do:
      indices.create:
        index: test-histogram
        body:
          settings:
            number_of_shards: 1
            number_of_replicas: 0
            index:
              mode: time_series
              routing_path: [ metricset, k8s.pod.uid ]
              time_series:
                start_time: 2021-04-28T00:00:00Z
                end_time: 2021-04-29T00:00:00Z
          mappings:
            properties:
              "@timestamp":
                type: date
              metricset:
                type: keyword
                time_series_dimension: true
              k8s:
                properties:
                  pod:
                    properties:
                      uid:
                        type: keyword
                        time_series_dimension: true
                      name:
                        type: keyword
                      latency:
                        type: histogram
                      network:
                        properties:
                          tx:
                            type: long
                            time_series_metric: gauge
                          rx:
                            type: long
                            time_series_metric: gauge
  - do:
      bulk:
        refresh: true
        index: test-histogram
        body:
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:50:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "network": {"tx": 2001818691, "rx": 802133794}, "latency": {"counts": [10, 12, 20, 5], "values": [1, 10, 100, 100]}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:55:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "network": {"tx": 2001819988, "rx": 802133911}, "latency": {"counts": [8, 7, 10, 12], "values": [1, 2, 5, 10]}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T19:00:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "network": {"tx": 1001818691, "rx": 502133794}, "latency": {"counts": [1, 5, 5, 22], "values": [1, 10, 100, 100]}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T19:05:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "network": {"tx": 1001822087, "rx": 502134222}, "latency": {"counts": [7, 15, 10, 10], "values": [1, 2, 5, 10]}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:51:20.467Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "network": {"tx": 1781818691, "rx": 533135238}, "latency": {"counts": [2, 4, 16, 4], "values": [1, 2, 5, 10]}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:56:20.467Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "network": {"tx": 1781818691, "rx": 533135567}, "latency": {"counts": [2, 2, 8, 8], "values": [1, 10, 100, 100]}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T19:01:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "network": {"tx": 1651818691, "rx": 487133866}, "latency": {"counts": [4, 5, 4, 13], "values": [1, 10, 100, 100]}}}}'

  - do:
      indices.put_settings:
        index: test-histogram
        body:
          index.blocks.write: true

---
"Downsample histogram as label":
  - skip:
      version: " - 8.4.99"
      reason: "rollup renamed to downsample in 8.5.0"

  - do:
      indices.downsample:
        index: test-histogram
        target_index: rollup-test-histogram
        body:  >
          {
            "fixed_interval": "1h"
          }
  - is_true: acknowledged

  - do:
      search:
        index: rollup-test-histogram
        body:
          sort: [ "_tsid", "@timestamp" ]

  - length: { hits.hits: 4 }
```

### Logs (if relevant)

_No response_
x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapper.java
};
            }
            @Override
            public boolean hasValue() {
                return binaryValue != null;
            }
            @Override
            public void write(XContentBuilder b) throws IOException {
                if (binaryValue == null) {
                    return;
                }
                b.startObject(simpleName());
                value.reset(binaryValue);
                b.startArray("values");
                while (value.next()) {
                    b.value(value.value());
                }
                b.endArray();
                value.reset(binaryValue);
                b.startArray("counts");
                while (value.next()) {
                    b.value(value.count());
                }
                b.endArray();
                b.endObject();
            }
        };
    }
}