Elapsed return no results

I started to work with InfluxDB OSS 2.7.1 and Java Client 6.7.0. I use flux to query my data and most of the things work out. I want to calculate the time difference between entries and thought that it would work out with elapsed().
My query returns 12 lines (which is correct):
from(bucket: “DB1”)
|> range(start: 0)
|> filter(fn: (r) => r[“_measurement”] == “Item”)
|> filter(fn: (r) => r[“id”] == “item1”)
|> filter(fn: (r) => r[“location”] != “”)
|> group(columns: [“_time”])
but if I add at the end the following:
|> elapsed(unit: 1ms)
I get no results.
Could someone tell me what my mistake/thinking error is?

In addition, sort(columns:[“_time”], desc:true) is also not working (which I would need to get the elapsed time for the right rows).

Thank you in advance!


Hi @sabine

I think the order of the functions is what is causing the issue. Try this:

from(bucket: "DB1")
  |> range(start: 0)
  |> filter(fn: (r) => r["_measurement"] == "Item")
  |> filter(fn: (r) => r["id"] == "tiem1")
  |> filter(fn: (r) => r["location"] != "")
  |> sort(columns: ["_value"], desc: true)  
  |> elapsed(unit: 1ms)  
  |> yield(name: "your-data")

I think you nailed the solution but is not really the order.

|> group(columns: [“_time”])

should not be there. grouping by time technically creates a “sub table” for each timestamp.
@sabine, since it is a time series grouping by time creates 12 groups of 1 row each, elapsed won’t return any result because you need more than 1 row to operate there is not any second time stamp to evaluate the elapsed time between them

Thanks a lot for your quick replies and explanations.
Unfortunately, your suggestions do not lead to success.

I used “group”, since “sort” had no influence on my results (I don’t know why) - it is always sorted by the location entries. Only with “group” I could achieve the correct order.
Even if I ignore once that sorting doesn’t work and don’t use “group”, elapsed(unit: 1ms) still does not return any data.

Can this be due to the basic settings of my InfluxDB?

Best regards,

I know what is going on with sort.

You are testing in the data explorer correct? For some reason the displayed values there is not correct but the data should be sorted you just cant see the correct order in data explorer. For example In grafana I can see the efect of sort in the table view.

Using sort by _time first you should get the time elapsed between records… what is the difference between timestamps? It will be easier to help with a sample of your data or at least a screenshot.


Thanks a lot for trying to help me.

Yes, I am testing in the data explorer but also running my queries from the Java client (same result).

The changes are in milliseconds.

In Grafana I cannot test my data since this table only consists of string values.

I am writing my points to the bucket with the Java client using the WriteAPIBlocking. I also tested it manually with the line protocol → sorting and elapsed is not working out

Getting the data from fluxQuery:
Query queryObj = new Query();
queryObj.setQuery(fluxQuery); //flux Query see first post
List result = influxDBClient.getQueryApi().query(queryObj);
for (FluxTable table : result) {
for (FluxRecord record : table.getRecords()) {

Looking at the screenshot of the data provided, there is a new table every time you send a new value. I think that may be your issue.

Remember what @fercasjr wrote:


Thanks a lot - Based on your hint, I found the issue (column location was the problem → everything is grouped by its entries.)
Without this column, sort() and elapsed() work out! :slight_smile: