List all tags with missing values for a certain field, in Flux

In Influx 2.x, using Flux, is there a way to report all distinct tags which have missing (null) data in certain fields?

Simply put, I want to list all ‘hardware_id’ keys which don’t have a value for field ‘heading’.

In plain old SQL, and perhaps Influx QL in v1.x, it would be the equivalent of something like this in pseudo code:

	# omited time range for brevity
	SELECT device_id
	FROM measurement 
	WHERE field = 'heading'
	AND _value is null;

I’ve tried fill()-ing it, to no avail:

from(bucket: "sandbox")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "metrics")
    |> filter(fn: (r) => r["_field"] == "heading")
	
    // fill empty records with an arbitrary value
    |> fill(column: "_value", value: -999.0)

    // attempt to filter on these empty records
    |> filter(fn: (r) => r["_value"] == -999.0)

And I’ve also noticed the exists operation, but the documentation part is unclear for me on how this can be applicable:

from(bucket: "sandbox")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "metrics")
    |> filter(fn: (r) => r["_field"] == "heading")
    |> filter(fn: (r) => ({
	      r with
	      human_readable:

	      	// does not work, not sure if this even makes sense?
	        if exists r._value then r["foo"] = true
	        else r["foo"] = false
    }))

Any help would be very much appreciated.

Hello @moriarty,
I believe you can just do:

|> from(bucket: "my bucket")
|> filter(fn: (r) =>  r._measurement == "measurement")
|> filter(fn: (r) =>  r._field == "heading")
|> filter(fn: (r) =>  not exists r._value)
|> group()
|> unique(column: "device_id")