Use the SDK multi-value data model to query the latest data
Updated at:
Copy as MD
Use multiFieldQueryLast() to retrieve the most recent data point for each field of a metric. Unlike the single-value model, you must specify the fields when building the LastPointSubQuery.
Parameters
| Parameter | Required | Description |
|---|---|---|
metric | Yes | The metric name, for example, "wind" |
fields | Yes | One or more fields of the metric, for example, "speed", "level", "temperature" |
tags | No | Tag-based filter conditions. Pass Collections.emptyMap() to skip tag filtering |
tupleFormat | No | Whether to return results in tuple format |
msResolution | No | Whether to use millisecond resolution for timestamps |
Query the latest data
The following example queries the latest values of the speed, level, and temperature fields from the wind metric, with no tag filtering.
Step 1: Build the field list.
List<String> fields = new ArrayList<>();
fields.add("speed");
fields.add("level");
fields.add("temperature");Step 2: Create a LastPointSubQuery with the metric, fields, and tag conditions.
// Pass Collections.emptyMap() as the tags argument when no tag filtering is needed.
LastPointSubQuery lastPointSubQuery = LastPointSubQuery.builder("wind", fields, Collections.emptyMap()).build();Step 3: Build the LastPointQuery.
LastPointQuery lastPointQuery = LastPointQuery.builder()
.sub(lastPointSubQuery)
.tupleFormat(true)
.msResolution(false)
.build();Step 4: Call multiFieldQueryLast() and retrieve the results.
List<MultiFieldQueryLastResult> results = tsdb.multiFieldQueryLast(lastPointQuery);Is this page helpful?