@@ -37,17 +37,17 @@ In your request, set the following:
37
37
The following example shows how to use cURL to send a Flux query to InfluxDB {{< current-version >}}:
38
38
39
39
{{% code-placeholders "ORG_ID|API_TOKEN|BUCKET_NAME" %}}
40
- ``` bash
40
+
41
41
{{< code-tabs-wrapper >}}
42
42
{{% code-tabs %}}
43
43
[ Without compression] ( # )
44
44
[ With compression] ( # )
45
45
{{% /code-tabs %}}
46
-
47
46
{{% code-tab-content %}}
48
47
``` bash
49
- curl --request POST \
50
- http://localhost:8086/api/v2/query? orgID=ORG_ID \
48
+ curl \
49
+ --request POST \
50
+ http://{{< influxdb/host > }}/api/v2/query? orgID=ORG_ID \
51
51
--header ' Authorization: Token API_TOKEN' \
52
52
--header ' Accept: application/csv' \
53
53
--header ' Content-type: application/vnd.flux' \
@@ -57,11 +57,11 @@ curl --request POST \
57
57
|> aggregateWindow(every: 1h, fn: mean)'
58
58
```
59
59
{{% /code-tab-content %}}
60
-
61
60
{{% code-tab-content %}}
62
61
``` bash
63
- curl --request POST \
64
- http://localhost:8086/api/v2/query? orgID=ORG_ID \
62
+ curl \
63
+ --request POST \
64
+ http://{{< influxdb/host > }}/api/v2/query? orgID=ORG_ID \
65
65
--header ' Authorization: Token API_TOKEN' \
66
66
--header ' Accept: application/csv' \
67
67
--header ' Content-type: application/vnd.flux' \
@@ -84,29 +84,45 @@ Replace the following with your values:
84
84
85
85
## Send an InfluxQL query request
86
86
87
- You can query InfluxDB {{< current-version > }} using the InfluxQL query language with the v1-compatible API.
88
- Send an InfluxQL query in an HTTP ` GET` or ` POST` request to the following endpoint:
87
+ To query InfluxDB {{< current-version >}} using the [ InfluxQL query language] ( /influxdb/v2/reference/syntax/influxql/ ) , send a request to the v1-compatible API endpoint:
88
+
89
+ {{% api-endpoint method="GET" endpoint="/query" api-ref="/influxdb/v2/api/v2/#operation/GetLegacyQuery" %}}
89
90
90
- {{% api-endpoint endpoint=" /query" api-ref=" /influxdb/v2/api/v2/#operation/GetLegacyQuery " %}}
91
+ {{% api-endpoint method="POST" endpoint="/query" api-ref="/influxdb/v2/api/v2/#operation/PostQueryV1 " %}}
91
92
92
93
In your request, set the following:
93
94
94
95
- [ 1.x-compatible or 2.x authentication] ( /influxdb/v2/api-guide/influxdb-1x/#authentication ) credentials
95
96
- Headers:
96
97
- ` Accept: application/csv ` or ` Accept: application/json `
97
98
- ` Content-type: application/vnd.influxql `
98
- - Your InfluxQL query text in the request body or the ` q` URL parameter
99
+ - The database and retention policy mapped to the bucket you want to query
100
+ - Your InfluxQL query text
99
101
100
102
> [ !Note]
101
103
> If you have an existing bucket that doesn't follow the ** database/retention-policy** naming convention,
102
104
> you ** must** [ manually create a database and retention policy mapping] ( /influxdb/v2/query-data/influxql/dbrp/#create-dbrp-mappings )
103
105
> to query that bucket with the ` /query ` compatibility API.
106
+ > Use the ` db ` and ` rp ` query parameters to specify the database and retention policy
107
+ > for the bucket you want to query.
108
+
109
+ > [ !Note]
110
+ > #### Use gzip to compress a large query response
111
+ >
112
+ > To compress the query response, set the ` Accept-Encoding ` header to ` gzip ` .
113
+ > This saves network bandwidth, but increases server-side load.
114
+ >
115
+ > We recommend only using gzip compression on responses that are larger than 1.4 KB.
116
+ > If the response is smaller than 1.4 KB, gzip encoding will always return a 1.4 KB
117
+ > response, despite the uncompressed response size.
118
+ > 1500 bytes (~ 1.4 KB) is the maximum transmission unit (MTU) size for the public
119
+ > network and is the largest packet size allowed at the network layer.
104
120
105
121
#### InfluxQL - Example query request
106
122
107
- The following example shows how to use cURL to send an InfluxQL query to InfluxDB {{< current-version >}} using 1.x compatible authentication:
123
+ The following example shows how to use cURL to send an InfluxQL query to InfluxDB {{< current-version >}} using v1- compatible authentication:
108
124
109
- {{% code-placeholders "API_TOKEN|BUCKET_NAME|RETENTION_POLICY_NAME " %}}
125
+ {{% code-placeholders "API_TOKEN|BUCKET_NAME" %}}
110
126
111
127
{{< code-tabs-wrapper >}}
112
128
{{% code-tabs %}}
@@ -115,35 +131,37 @@ The following example shows how to use cURL to send an InfluxQL query to InfluxD
115
131
{{% /code-tabs %}}
116
132
117
133
{{% code-tab-content %}}
134
+
118
135
``` bash
119
136
# 1.x compatible POST request using Basic authentication and InfluxQL
120
137
curl --request POST \
121
- "http://localhost:8086/ query?db=BUCKET_NAME&rp=RETENTION_POLICY &p=API_TOKEN&u=ignored" \
138
+ " http://{{< influxdb/host >}}/ query?db=BUCKET_NAME&p=API_TOKEN&u=ignored" \
122
139
--header " Content-type: application/vnd.influxql" \
123
- --data "SELECT * FROM home WHERE time < now()"
140
+ --data " SELECT * FROM home WHERE time > now() - 1h "
124
141
```
125
142
{{% /code-tab-content %}}
126
143
{{% code-tab-content %}}
144
+
127
145
``` bash
128
146
# 1.x compatible GET request using Basic authentication and InfluxQL
129
- curl --get "http://localhost:8086 /query" \
147
+ curl --get " http://{{< influxdb/host >}} /query" \
130
148
--header " Accept: application/json" \
131
- --data-urlencode "q=SELECT * FROM home WHERE time < now()" \
149
+ --data-urlencode " q=SELECT * FROM home WHERE time > now() - 1h " \
132
150
--data-urlencode " db=BUCKET_NAME" \
133
- --data-urlencode "rp=RETENTION_POLICY" \
134
151
--data-urlencode " u=ignored" \
135
152
--data-urlencode " p=API_TOKEN"
136
153
```
137
154
{{% /code-tab-content %}}
138
155
{{< /code-tabs-wrapper >}}
139
156
140
157
{{% /code-placeholders %}}
158
+
141
159
Replace the following with your values:
160
+
142
161
- {{% code-placeholder-key %}}` API_TOKEN ` {{% /code-placeholder-key %}} - your [ token] ( /influxdb/version/admin/tokens/ ) .
143
- - {{% code-placeholder-key %}}`BUCKET_NAME`{{% /code-placeholder-key %}} - the name of the [bucket](/influxdb/version/admin/buckets/) to create.
144
- - {{% code-placeholder-key %}}`RETENTION_POLICY_NAME`{{% /code-placeholder-key %}} - the name of the 1.x retention policy to use for the query.
162
+ - {{% code-placeholder-key %}}` BUCKET_NAME ` {{% /code-placeholder-key %}} - the name of the [ bucket] ( /influxdb/version/admin/buckets/ ) to query.
145
163
146
- {{% code-placeholders "ORG_ID|API_TOKEN|BUCKET_NAME|RETENTION_POLICY_NAME " %}}
164
+ {{% code-placeholders "ORG_ID|API_TOKEN|BUCKET_NAME" %}}
147
165
148
166
{{< code-tabs-wrapper >}}
149
167
{{% code-tabs %}}
@@ -153,11 +171,10 @@ Replace the following with your values:
153
171
154
172
{{% code-tab-content %}}
155
173
``` bash
156
- curl --get "http://localhost:8086 /query" \
174
+ curl --get " http://{{< influxdb/host >}} /query" \
157
175
--header ' Accept: application/csv' \
158
176
--header ' Content-type: application/json' \
159
177
--data-urlencode " db=BUCKET_NAME" \
160
- --data-urlencode "rp=RETENTION_POLICY_NAME" \
161
178
--data-urlencode " p=API_TOKEN" \
162
179
--data-urlencode " u=ignored" \
163
180
--data-urlencode " q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1"
@@ -166,27 +183,23 @@ curl --get "http://localhost:8086/query" \
166
183
{{% code-tab-content %}}
167
184
168
185
``` bash
169
- curl --get "http://localhost:8086 /query" \
186
+ curl --get " http://{{< influxdb/host >}} /query" \
170
187
--header ' Accept: application/csv' \
171
188
--header ' Content-type: application/json' \
172
189
--header ' Accept-Encoding: gzip' \
173
190
--data-urlencode " db=BUCKET_NAME" \
174
- --data-urlencode "rp=RETENTION_POLICY_NAME" \
175
191
--data-urlencode " p=API_TOKEN" \
176
192
--data-urlencode " u=ignored" \
177
193
--data-urlencode " q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1"
178
194
```
179
- ```
180
195
{{% /code-tab-content %}}
181
196
{{< /code-tabs-wrapper >}}
182
197
183
198
{{% /code-placeholders %}}
184
199
185
200
Replace the following with your values:
186
201
187
- - {{% code-placeholder-key %}}`ORG_ID`{{% /code-placeholder-key %}} - the ID of the [organization](/influxdb/version/admin/organizations/) that owns the bucket.
188
202
- {{% code-placeholder-key %}}` API_TOKEN ` {{% /code-placeholder-key %}} - your [ token] ( /influxdb/version/admin/tokens/ ) .
189
203
- {{% code-placeholder-key %}}` BUCKET_NAME ` {{% /code-placeholder-key %}} - the name of the [ bucket] ( /influxdb/version/admin/buckets/ ) to create.
190
- - {{% code-placeholder-key %}}`RETENTION_POLICY_NAME`{{% /code-placeholder-key %}} - the name of the 1.x retention policy to use for the query.
191
204
192
205
InfluxDB returns the query results in [ annotated CSV] ( /influxdb/version/reference/syntax/annotated-csv/ ) .
0 commit comments