First off, I’m new to influxdb.
I’m storing data in an influxdb using python, I can see that the data is stored the correct way.
But I can’t figure out how to get all records for a measurement between to timestamps.
In other words getting all tags and fields like a python dict.
I am no sure I understood your question. If you are trying to query data from the InfluxDB UI using flux, the query goes like this:
|> range(start: timestamp1, stop: timestamp2)
|> filter(fn: (r) => r._measurement == “your_measurement”)
This will yield a stream of tables, grouped by columns in which rows have the same values (tags, fields, measurement…)
Is this your question or are you trying to do something else?
I’m not sure how to read the result from influx.
If I insert following data
tags: [“a”: 1, “b”: 2], fields: [“c”: 3, “d”: 4]
I wish to have an result
[“a”: 1, “b”: 2, “c”: 3, “d”: 4]
I see what you mean but I think you are mixing definitions here.
The fields are the structure that record metadata and the actual data value. These data structures are composed of key-value pairs. For example, if I am recording the temperature and pressure of a room, “temperature” and “pressure” are the field keys, while 23ºC and 101,325 Pa are the respective field values. In influx, at least one field is required, but these are not indexed, which means that querying by field will yield all points within the time range, which is not performant relative to tags
On the other hand, tags are the strings that store metadata, which gives you information about the source of the data or any other that allows to distinguish between values (i.e.: the device that produced the data). As opposed to fields, tag values are indexed, so queries on tag values are performant. Following the example from before, I could add a tag key called ‘rooms’ where tag values could be the different rooms of a house: kitchen, bedroom, living room, etc. By doing so, I could query the temperature and pressure from a selected room:
|> range(start: timestamp1)
This would yield all the values of temperature and pressure from the kitchen.
Basically, fields are the actual values of your time-series, while the tags are associated metadata that allow you to make distinctions and, therefore, query better from your data.
You can find more information on this here.
thanks for explaining
is it possible to convert a field to a tag?
I was thinking
Even though I might be using influx in an none intended way, is it possible to produce the result I wish to have with the help of grouping and pivoting? (or other functions)
So basically what you are trying to do is locate one single record and extract it as a dict? If what you want to do so you can use the getRecord function.
Is that what you were trying to do? Or are you trying to get all the possible key-value combinations for the records within a time period?
I’m trying to get the data out in dicts in the same order I inserted it like this:
time: 1, tags: [“a”: 1, “b”: 2], fields: [“c”: 3, “d”: 4]
time: 2, tags: [“a”: 2, “b”: 1], fields: [“c”: 4, “d”: 5]
time: 3, tags: [“a”: 4, “b”: 3], fields: [“c”: 1, “d”: 2]
The requested data would be:
[“time”: 1, “a”: 1, “b”: 2, “c”: 3, “d”: 4]
[“time”: 2, “a”: 2, “b”: 1, “c”: 4, “d”: 5]
[“time”: 3, “a”: 4, “b”: 3, “c”: 1, “d”: 2]
Sorry if I was unclear, I had it like this with an earlier version (1.8 I think) of influxdb and I have a massive project that needs the data like that.
Edit: I forgot to say that the timestamps are not always unique.
After talking to a person I have realised that a tag is the problem.
Is it possible to remove a tag/rebuild a measurement somehow?
I have gotten the data in the way I wan’t to… kind of.
I ask for 8 hours of data and get the last data repeated thousands of times with timestamps a few microseconds apart.
Using the Data Explorer (included in influxdb) gives me the result I’m after with the same (copy pasted) query, but when I get the data in python it’s not the same.
I don’t really know what is going in your code, but have you checked out this pages?
In here you can find documentation about the python client.
And here you can find a tutorial to get started with Python and InfluxDB v2.0
Let me know if this helps, otherwise, only by letting me know the problems without seeing the code I cannot really be of much help.
Thanks so much for the time you took to help me.
I hade a faulty datetime format.