influxdbinfluxql

How to query all measurements in InfluxDB where a value from one measurement equals X


I query all measurements from Influx database like so:

http://localhost:8086/query?pretty=true&db=boatdata&q=SELECT value FROM /.*/ LIMIT 1

Works fine. However, instead of LIMIT 1 I need to get values for all the measurements where value from one measurement=x, so I’d expect something like SELECT value FROM /.*/ WHERE measurement1.value=x but it doesn’t work. I hope it makes sense. Any idea how to make it work? Thanks.

...to explain it better: in the first query (http://localhost…) I listed in this post I get a 1 record for all the measurements. But I want to get 1 record for all the measurements where value from measurement1 (one of the measurements) equals X.


Solution

  • This is impossible using InfluxQL. All measurements you ask are different series of data - so they are not grouped together in one table. Idea of InfluxDB is that measurements are separate "tables" which are indexed by time and tag keys. I suggest you change your database architecture by writing values into different value fields. You should have your data in one measurement to make query like you want. You can move all your data from other measurements to one measurement for example by:

    select "value" as "value1" from "measurement1" into "measurement" group by *

    For each "measurement1" moved into "measurement" which will collect many value fields. Then you will be able to make a query:

    select * from "measurement" where "value1"=5

    The query above should give you all value fields moved into "measurement" with the same timestamp where field "value1"=5. Tip: If you have value1,value2,value3 in your measurement then you can use regex like:

    select /value/ from "measurement" where "value1"=5

    To avoid receiving tag key values or field values which you do not want.