You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--data "SELECT * FROM cpu_usage WHERE time > now() - 1h"
145
+
```
146
+
150
147
##### Query a non-default retention policy
151
148
149
+
The following example:
150
+
151
+
- sends a `GET` request to the `/query` endpoint
152
+
- uses the `Authorization` header with the `Token` scheme (compatible with InfluxDB 2.x) to provide the API token
153
+
- queries a custom retention policy mapped for the database
154
+
152
155
<!--test:setup
153
156
```sh
154
157
service influxdb start && \
@@ -162,43 +165,56 @@ influx setup \
162
165
-->
163
166
164
167
```sh
165
-
curl --get http://localhost:8086/query \
168
+
curl --get http://{{< influxdb/host >}}/query \
166
169
--header "Authorization: Token API_TOKEN" \
167
-
--data-urlencode "db=mydb" \
168
-
--data-urlencode "rp=customrp" \
170
+
--data-urlencode "db=DATABASE_NAME" \
171
+
--data-urlencode "rp=RETENTION_POLICY_NAME" \
169
172
--data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1"
170
173
```
171
174
172
175
##### Execute multiple queries
173
176
174
177
```sh
175
-
curl --get http://localhost:8086/query \
178
+
curl --get http://{{< influxdb/host >}}/query \
176
179
--header "Authorization: Token API_TOKEN" \
177
-
--data-urlencode "db=mydb" \
180
+
--data-urlencode "db=DATABASE_NAME" \
178
181
--data-urlencode "q=SELECT * FROM mem WHERE host=host1;SELECT mean(used_percent) FROM mem WHERE host=host1 GROUP BY time(10m)"
179
182
```
180
183
181
184
##### Return query results with millisecond Unix timestamps
182
185
```sh
183
-
curl --get http://localhost:8086/query \
186
+
curl --get http://{{< influxdb/host >}}/query \
184
187
--header "Authorization: Token API_TOKEN" \
185
-
--data-urlencode "db=mydb" \
186
-
--data-urlencode "rp=myrp" \
188
+
--data-urlencode "db=DATABASE_NAME" \
189
+
--data-urlencode "rp=RETENTION_POLICY_NAME" \
187
190
--data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1" \
188
191
--data-urlencode "epoch=ms"
189
192
```
190
193
191
194
##### Execute InfluxQL queries from a file
192
195
```sh
193
-
curl --get http://localhost:8086/query \
196
+
curl --get http://{{< influxdb/host >}}/query \
194
197
--header "Authorization: Token API_TOKEN" \
195
-
--data-urlencode "db=mydb" \
196
-
--data-urlencode "q@path/to/influxql.txt" \
197
-
--data-urlencode "async=true"
198
+
--data-urlencode "db=DATABASE_NAME" \
199
+
--data-urlencode "q@path/to/influxql.txt"
198
200
```
199
201
202
+
##### Return a gzip-compressed response
203
+
```sh
204
+
curl --get http://{{< influxdb/host >}}/query \
205
+
--header 'Accept-Encoding: gzip' \
206
+
--header "Authorization: Token API_TOKEN" \
207
+
--data-urlencode "db=DATABASE_NAME" \
208
+
--data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1"
209
+
```
200
210
{{% /code-placeholders %}}
201
211
202
212
Replace the following:
203
213
204
214
- {{% code-placeholder-key %}}`API_TOKEN`{{% /code-placeholder-key %}}: your InfluxDB [API token](/influxdb/v2/admin/tokens/)
215
+
- {{% code-placeholder-key %}}`DATABASE_NAME`{{% /code-placeholder-key %}}: the name of the database to query.
216
+
In InfluxDB 2.x, databases and retention policies map to [buckets](/influxdb/v2/admin/buckets/).
217
+
- {{% code-placeholder-key %}}`RETENTION_POLICY_NAME`{{% /code-placeholder-key %}}: the name of the retention policy to query.
218
+
In InfluxDB 2.x, databases and retention policies map to [buckets](/influxdb/v2/admin/buckets/).
219
+
220
+
_For more information about the database and retention policy mapping, see [Database and retention policy mapping](/influxdb/v2/reference/api/influxdb-1x/dbrp)._
0 commit comments