Query data influx

Hello,

Please for querying data with flux into Influxdb2.0, can I query from a predefined variable ?
option = “275” and sometimes option =“269”. It depends the user choice.

query = 'from(bucket: "POC")|> range(start: -30d)|> filter(fn: (r) => r._measurement == option)'

I also tried these two syntax but they don’t work.

 query = 'from(bucket: "POC")|> range(start: -30d)|> filter(fn: (r) => r._measurement == ${option})

query = ‘from(bucket: “POC_Nomenclatures”)|> range(start: -30d)|> filter(fn: ® => r._measurement =~ /option/)’

Thanks for your support.

I think so, though I’ve not used it myself. Eg, if you made a variable for user to specify the bucket, you’d reference that in flux as

v.bucket

You would likely want to use the map variable type, so that you can use a more meaningful name than 269 or 273 for the users to select.

Take a look at these pages

https://docs.influxdata.com/influxdb/v2.0/visualize-data/variables/

https://docs.influxdata.com/influxdb/v2.0/visualize-data/variables/create-variable/

https://docs.influxdata.com/influxdb/v2.0/visualize-data/variables/variable-types/

Hello,

Thank you for your reply but the query that I want to do comes from a user choice. It doesn’t exist into another bucket.

Thanks.

Go to InfluxDB 2.0 UI
Settings > Variables > Create Variables
Enter a name (be careful, some names are keyword and not allowed), select Type CSV, enter the values (see example below).
Afterwards it should be possible to access this variable in flux with v._option (in my example) and also in the dashboard as dropdown selection.

Thank you so much. It wasn’t clear in the documentation.