﻿---
title: Metadata functions
description: PromQL metadata functions in Elasticsearch that derive labels from existing label values or from a selector.
url: https://www.elastic.co/elastic/docs-builder/docs/5051/reference/query-languages/promql/functions/metadata
products:
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Planned
---

# Metadata functions
These functions work on the labels of a result: `label_join` and `label_replace` derive a new label, or overwrite an existing one, from the values of other labels, and `absent` returns a series whose labels come from its selector's equality matchers.

## `absent`

<applies-to>Elastic Stack: Planned</applies-to>
Returns an empty vector if the instant vector argument has any element, and a single-element vector with the value `1` otherwise.
When the argument is a selector, the result carries the labels of its equality matchers, such as `job="api"` for `absent(http_requests_total{job="api"})`. A label takes the value of its first equality matcher, and is left out when a later matcher names it too, such as `job` in `absent(x{job="api", job!="web"})`. Any other argument gives a result without labels.
The query needs a time range (`start` and `end`, `time`, or a `@timestamp` range filter on the request), because `absent` returns a value at the evaluation steps where the argument has no element.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
absent(http_requests_total{job="api"})
```

<note>
  **Differences from Prometheus**`absent` as an operand of an arithmetic or comparison operator whose other operand reads data, such as `absent(a) + b`, isn't supported yet. Scalar operands, such as `absent(a) * 2`, and the `or` operator, such as `a or absent(b)`, are supported, unless the other operand has a label of the same name mapped as a type other than `keyword`, such as `sum by (shard) (x) or absent(x{shard="7"})` where `shard` is a `long` field. An equality matcher on a label named `step` or on the value column, such as `absent(x{step="a"})` or `result=(absent(x{result="ok"}))`, isn't supported yet.
</note>


## `label_join`

<applies-to>Elastic Stack: Planned</applies-to>
Joins the values of the source labels `src_label_1` .. `src_label_N` using `separator` and stores the result in the label `dst_label`. A missing source label contributes an empty string.
The destination can be a new label or an existing stored label (a dimension or `__name__`).
<applies-to>Elastic Stack: Planned</applies-to> <applies-to>Elastic Cloud Serverless: Generally available</applies-to> A call over a `by(...)` aggregation, directly or under `topk`, `bottomk`, `limitk`, or `limit_ratio`, or over `count_values`, is supported when the destination is a new label, such as `label_replace(sum by (job) (x), "dst", "$1", "job", "(.*)")`.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
  <definition term="dst_label (scalar)">
    Name of the label to set.
  </definition>
  <definition term="separator (scalar)">
    String inserted between the source values.
  </definition>
  <definition term="src_label (scalar)">
    Name of a label to join (repeatable).
  </definition>
</definitions>

**Example**
```
sum by (endpoint) (label_join(http_requests_total, "endpoint", "/", "job", "instance"))
```

<note>
  **Differences from Prometheus**A call that isn't aggregated or is under `without(...)`, and a destination label named `step`, which is an output column of the `PROMQL` command, aren't supported yet.<applies-to>Elastic Stack: Planned</applies-to> A call over an aggregation, such as `label_replace(sum by (job) (x), ...)`, isn't supported yet.<applies-to>Elastic Stack: Planned</applies-to> <applies-to>Elastic Cloud Serverless: Generally available</applies-to> A call over anything other than a `by(...)` aggregation or `count_values`, such as `sum(x)`, a `without(...)` aggregation, `topk`, or a binary operator, and a call that overwrites a grouping label or the `count_values` label, such as `label_replace(sum by (job) (x), "job", "$1", "job", "(.*)")`, aren't supported yet. Write a new label instead.Reading or overwriting `__name__` behaves like Prometheus only for Prometheus-style data that stores `__name__` as a label; for OpenTelemetry-style metrics the metric name is not exposed as a readable or writable label here.
</note>


## `label_replace`

<applies-to>Elastic Stack: Planned</applies-to>
Matches the regular expression `regex` against the value of the label `src_label`. On a match, sets the label `dst_label` to the expansion of `replacement`, substituting `$1`, `$name`, and `${name}` with the matched capture groups; on no match the input series is returned unchanged.
The destination can be a new label or an existing stored label (a dimension or `__name__`). Regular expressions use the RE2 engine (RE2 syntax including `(?P<name>)`, `$1`/`$name`/`${name}` replacement expansion, no backreferences, fully anchored as `^(?s:regex)$`), matching Prometheus.
<applies-to>Elastic Stack: Planned</applies-to> <applies-to>Elastic Cloud Serverless: Generally available</applies-to> A call over a `by(...)` aggregation, directly or under `topk`, `bottomk`, `limitk`, or `limit_ratio`, or over `count_values`, is supported when the destination is a new label, such as `label_replace(sum by (job) (x), "dst", "$1", "job", "(.*)")`.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
  <definition term="dst_label (scalar)">
    Name of the label to set.
  </definition>
  <definition term="replacement (scalar)">
    Replacement value, with `$1`/`$name`/`${name}` capture-group expansion.
  </definition>
  <definition term="src_label (scalar)">
    Name of the label to read.
  </definition>
  <definition term="regex (scalar)">
    Regular expression matched against `src_label`.
  </definition>
</definitions>

**Example**
```
sum by (job2) (label_replace(http_requests_total, "job2", "$1", "job", "(.*)-server"))
```

<note>
  **Differences from Prometheus**A call that isn't aggregated or is under `without(...)`, and a destination label named `step`, which is an output column of the `PROMQL` command, aren't supported yet.<applies-to>Elastic Stack: Planned</applies-to> A call over an aggregation, such as `label_replace(sum by (job) (x), ...)`, isn't supported yet.<applies-to>Elastic Stack: Planned</applies-to> <applies-to>Elastic Cloud Serverless: Generally available</applies-to> A call over anything other than a `by(...)` aggregation or `count_values`, such as `sum(x)`, a `without(...)` aggregation, `topk`, or a binary operator, and a call that overwrites a grouping label or the `count_values` label, such as `label_replace(sum by (job) (x), "job", "$1", "job", "(.*)")`, aren't supported yet. Write a new label instead.Reading or overwriting `__name__` behaves like Prometheus only for Prometheus-style data that stores `__name__` as a label; for OpenTelemetry-style metrics the metric name is not exposed as a readable or writable label here.
</note>