Skip to content

Commit b4ab790

Browse files
committed
Fix hosts, cleanup retention policy
1 parent 2f59c19 commit b4ab790

File tree

1 file changed

+41
-28
lines changed
  • content/shared/influxdb-v2/query-data/execute-queries

1 file changed

+41
-28
lines changed

content/shared/influxdb-v2/query-data/execute-queries/influx-api.md

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ In your request, set the following:
3737
The following example shows how to use cURL to send a Flux query to InfluxDB {{< current-version >}}:
3838

3939
{{% code-placeholders "ORG_ID|API_TOKEN|BUCKET_NAME" %}}
40-
```bash
40+
4141
{{< code-tabs-wrapper >}}
4242
{{% code-tabs %}}
4343
[Without compression](#)
4444
[With compression](#)
4545
{{% /code-tabs %}}
46-
4746
{{% code-tab-content %}}
4847
```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 \
5151
--header 'Authorization: Token API_TOKEN' \
5252
--header 'Accept: application/csv' \
5353
--header 'Content-type: application/vnd.flux' \
@@ -57,11 +57,11 @@ curl --request POST \
5757
|> aggregateWindow(every: 1h, fn: mean)'
5858
```
5959
{{% /code-tab-content %}}
60-
6160
{{% code-tab-content %}}
6261
```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 \
6565
--header 'Authorization: Token API_TOKEN' \
6666
--header 'Accept: application/csv' \
6767
--header 'Content-type: application/vnd.flux' \
@@ -84,29 +84,45 @@ Replace the following with your values:
8484

8585
## Send an InfluxQL query request
8686

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" %}}
8990

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" %}}
9192

9293
In your request, set the following:
9394

9495
- [1.x-compatible or 2.x authentication](/influxdb/v2/api-guide/influxdb-1x/#authentication) credentials
9596
- Headers:
9697
- `Accept: application/csv` or `Accept: application/json`
9798
- `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
99101

100102
> [!Note]
101103
> If you have an existing bucket that doesn't follow the **database/retention-policy** naming convention,
102104
> you **must** [manually create a database and retention policy mapping](/influxdb/v2/query-data/influxql/dbrp/#create-dbrp-mappings)
103105
> 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.
104120
105121
#### InfluxQL - Example query request
106122

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:
108124

109-
{{% code-placeholders "API_TOKEN|BUCKET_NAME|RETENTION_POLICY_NAME" %}}
125+
{{% code-placeholders "API_TOKEN|BUCKET_NAME" %}}
110126

111127
{{< code-tabs-wrapper >}}
112128
{{% code-tabs %}}
@@ -115,35 +131,37 @@ The following example shows how to use cURL to send an InfluxQL query to InfluxD
115131
{{% /code-tabs %}}
116132

117133
{{% code-tab-content %}}
134+
118135
```bash
119136
# 1.x compatible POST request using Basic authentication and InfluxQL
120137
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" \
122139
--header "Content-type: application/vnd.influxql" \
123-
--data "SELECT * FROM home WHERE time < now()"
140+
--data "SELECT * FROM home WHERE time > now() - 1h"
124141
```
125142
{{% /code-tab-content %}}
126143
{{% code-tab-content %}}
144+
127145
```bash
128146
# 1.x compatible GET request using Basic authentication and InfluxQL
129-
curl --get "http://localhost:8086/query" \
147+
curl --get "http://{{< influxdb/host >}}/query" \
130148
--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" \
132150
--data-urlencode "db=BUCKET_NAME" \
133-
--data-urlencode "rp=RETENTION_POLICY" \
134151
--data-urlencode "u=ignored" \
135152
--data-urlencode "p=API_TOKEN"
136153
```
137154
{{% /code-tab-content %}}
138155
{{< /code-tabs-wrapper >}}
139156

140157
{{% /code-placeholders %}}
158+
141159
Replace the following with your values:
160+
142161
- {{% 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.
145163

146-
{{% code-placeholders "ORG_ID|API_TOKEN|BUCKET_NAME|RETENTION_POLICY_NAME" %}}
164+
{{% code-placeholders "ORG_ID|API_TOKEN|BUCKET_NAME" %}}
147165

148166
{{< code-tabs-wrapper >}}
149167
{{% code-tabs %}}
@@ -153,11 +171,10 @@ Replace the following with your values:
153171

154172
{{% code-tab-content %}}
155173
```bash
156-
curl --get "http://localhost:8086/query" \
174+
curl --get "http://{{< influxdb/host >}}/query" \
157175
--header 'Accept: application/csv' \
158176
--header 'Content-type: application/json' \
159177
--data-urlencode "db=BUCKET_NAME" \
160-
--data-urlencode "rp=RETENTION_POLICY_NAME" \
161178
--data-urlencode "p=API_TOKEN" \
162179
--data-urlencode "u=ignored" \
163180
--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" \
166183
{{% code-tab-content %}}
167184

168185
```bash
169-
curl --get "http://localhost:8086/query" \
186+
curl --get "http://{{< influxdb/host >}}/query" \
170187
--header 'Accept: application/csv' \
171188
--header 'Content-type: application/json' \
172189
--header 'Accept-Encoding: gzip' \
173190
--data-urlencode "db=BUCKET_NAME" \
174-
--data-urlencode "rp=RETENTION_POLICY_NAME" \
175191
--data-urlencode "p=API_TOKEN" \
176192
--data-urlencode "u=ignored" \
177193
--data-urlencode "q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1"
178194
```
179-
```
180195
{{% /code-tab-content %}}
181196
{{< /code-tabs-wrapper >}}
182197

183198
{{% /code-placeholders %}}
184199

185200
Replace the following with your values:
186201

187-
- {{% code-placeholder-key %}}`ORG_ID`{{% /code-placeholder-key %}} - the ID of the [organization](/influxdb/version/admin/organizations/) that owns the bucket.
188202
- {{% code-placeholder-key %}}`API_TOKEN`{{% /code-placeholder-key %}} - your [token](/influxdb/version/admin/tokens/).
189203
- {{% 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.
191204

192205
InfluxDB returns the query results in [annotated CSV](/influxdb/version/reference/syntax/annotated-csv/).

0 commit comments

Comments
 (0)