2.0: Query all meassurements with specific tag

Hi guys,

I am evaluating Influx 2.0 and can’t find a good way to extract measurements. Maybe someone can point me in the right direction?

What I am trying to do?:
I want to get all measurements that contain a specific tag.

What did I try?
I tried the example here: https://www.influxdata.com/blog/schema-queries-in-ifql/#respond
In my understanding that would give me all measurements as a start. But the example doesn’t seem to work?
I use the java client library with the following code:

queryApi.query("from(bucket:\"opennms\")\n" +
                "  |> range(start:-24h)\n" +
                "  |> group(by:[\"_measurement\"])\n" +
                "  |> distinct(column:\"_measurement\")\n" +
                "  |> group(none:true)");

The error I get is:
type error 3:6-3:32: function does not take a parameter "by", required params ∅
Is the example broken?

What would be an efficient way to get all measurements (ideally including all their tags) that contain a specific tag?

Here is my nasty workaround:

Any ideas are appreciated!

Hi @Patrick_Schweizer,

thanks for using java client.

Did you try something like:

import "influxdata/influxdb/v1"

  bucket: "opennms",
  tag: "_measurement",
  predicate: (r) => exists r["tag_key"],
  start: duration(v: uint(v: 1970) - uint(v: now()))



Hello Bednar,
thank you for your reply!

I am not sure I understand your answer. I tried the example from the documentation:

  |> range(start:-24h)
  |> group(by:["_measurement"])
  |> distinct(column:"_measurement")
  |> group(none:true)

This doesn’t seem to work.

I am trying to apply your example but I can’t get it to work either. How do I apply your example?
This is how I start:

        InfluxDBClientOptions options = InfluxDBClientOptions.builder()
        influxDBClient = InfluxDBClientFactory.create(options);
        influxDBClient.getQueryApi().query("here goes the query");

I am not sure what String to put for “here goes the query”.

If I put there your example

String query = "bucket: \"opennms\"\n" +
                "  |> tag: \"_measurement\"\n" +
                "  |> predicate: (r) => exists r[\"tag_key\"]\n" +
                "  |> start: duration(v: uint(v: 1970) - uint(v: now()))\n";

I get:

compilation failed: loc 1:7-1:8: invalid statement @1:7-1:8:

I assume I am understanding something wrong?
Thanks for your help!

to make it a bit clearer I extracted the functionality to have a stand alone test for the problem:

You can clone the repo and run the test with maven test

Please take a look at this part:

Here you see what I am trying to query. The question is what should be instead in the query string?