Search code examples
influxdbinfluxdb-2flux-influxdb

How do I limit records for Influx using flux?


I'm new with Influx, and although I can get range, filter, sort and group to work, I just can't get limit to work.

I'm using Influx OSS 2.3 and I'd assume the query should look like this:

from(bucket: "readings") 
    |> range(start: - 1d) 
    |> limit(n:10)

I've tried both through the Data explorer and the C# sdk, but it always returns 400 records.

If I use offset I'm not getting any records:

from(bucket: "readings") 
    |> range(start: - 1d) 
    |> limit(n:10, offset:2)

Thanks for the help


Solution

  • I believe @alespour was on the right track. If you have tags, these will implicitly group the data into independent tables. In flux, each operation is applied to each table independently, so if you have 40 distinct tag values, a call to limit(n: 10) would return 400.

    Using group() with no arguments will drop grouping and the number of records you specify will be applied to all results.

    from(bucket: "readings") 
        |> range(start: - 1d) 
        |> group()
        |> limit(n:10)