Understanding Tags and Fields in InfluxDB


Written on December 1, 2024

In InfluxDB, tags and fields are essential components used to organize and query time-series data. Here’s a detailed explanation of each:


Tags

Definition

Tags are key-value pairs used to categorize and filter time-series data. Tags are indexed, making them ideal for querying and grouping data efficiently.

Characteristics

  • Stored as strings.
  • Indexed for fast queries.
  • Best suited for data with a finite number of unique values (e.g., categories, labels).

Example

If you’re storing temperature data from sensors in multiple locations:

  • Tag Key: location
  • Tag Value: office, warehouse, store

Fields

Definition

Fields are key-value pairs that store the actual measurements or values of the data. Fields are not indexed, so they are optimized for storage and retrieval rather than filtering.

Characteristics

  • Can store strings, integers, floats, or booleans.
  • Not indexed (slower for filtering compared to tags).
  • Used for storing metric or measurement values.

Example

In the same temperature dataset:

  • Field Key: temperature
  • Field Value: 23.5, 25.0, 22.8

Comparison Table

Aspect Tags Fields
Purpose Categorization and filtering Storing metric values (measurements)
Indexing Indexed (fast for queries) Not indexed (optimized for storage)
Value Type Strings Strings, integers, floats, booleans
Example location=office temperature=23.5

By understanding the difference between tags and fields, you can design your InfluxDB schema to balance performance and storage efficiency effectively.