1

We need to convert field to tag in influxDB v2.0 but not able to find any proper solution. Can someone help me out to achieve the same ?

Solution we found was to create new measurement by altering fields and tags of existing measurement but not able achieve it using Flux language.

Using below flux query we can copy the data from one measurement to another but not able to change the field to tag while adding data in new measurement.

from(bucket: "bucket_name")
    |> range(start: -10y)
    |> filter(fn: (r) => r._measurement == "cu_om")
    |> aggregateWindow(every: 5s, fn: last, createEmpty: false)
    |> yield(name: "last")
    |> set(key: "_measurement", value: "cu_om_new1")
    |> to(org: "org_name", bucket: "bucket_name")

Any help appreciated.

Dhyanesh Naik
  • 41
  • 1
  • 5

2 Answers2

0

Have a look at writing pivoted data to InfluxDB, maybe that's what you need. Using this method, you have control over which columns are written as fields and which as tags:

Use experimental.to() to write pivoted data to InfluxDB. Input data must have the following columns:

_time

_measurement

All columns in the group key other than _time and _measurement are written to InfluxDB as tags. Columns not in the group key are written to InfluxDB as fields.

alespour
  • 397
  • 1
  • 5
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 01 '21 at 14:10
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/29970563) – Muhammad Dyas Yaskur Oct 01 '21 at 17:38
0

You're almost there with your original code, there are extra fields with the to() function that allow this. If you have a set of data already where you have a tag name as value, you can specify it as a tagColumn in to(). Also, the new tag(s) must be string(s).

|> to(bucket: "NewBucketName",
   tagColumns: ["NewTagName"],
   fieldFn: (r) => ({"SomeValue": r._value })
   )
FractalDoctor
  • 2,496
  • 23
  • 32