Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
Use fenced code block
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-chen committed Dec 5, 2019
1 parent f1eba13 commit c6a697a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/sql/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ You can send HTTP GET request with your query embedded in URL parameter.

SQL query:

```console
>> curl -H 'Content-Type: application/json' -X GET localhost:9200/_opendistro/_sql?sql=SELECT * FROM accounts
```

## POST

Expand All @@ -48,9 +50,11 @@ You can also send HTTP POST request with your query in request body.

SQL query:

```console
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql -d '{
"query" : "SELECT * FROM accounts"
}'
```

## Explain

Expand All @@ -65,12 +69,15 @@ directly.

Explain query:

```console
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql/_explain -d '{
"query" : "SELECT firstname, lastname FROM accounts WHERE age > 20"
}'
```

Explain:

```json
{
"from" : 0,
"size" : 200,
Expand Down Expand Up @@ -109,3 +116,4 @@ Explain:
"excludes" : [ ]
}
}
```
4 changes: 4 additions & 0 deletions docs/sql/monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ The meaning of fields in the response is as follows:

SQL query:

```console
>> curl -H 'Content-Type: application/json' -X GET localhost:9200/_opendistro/_sql/stats
```

Result set:

```json
{
"failed_request_count_cb" : 0,
"failed_request_count_cuserr" : 0,
Expand All @@ -55,3 +58,4 @@ Result set:
"request_count" : 0,
"failed_request_count_syserr" : 0
}
```
28 changes: 28 additions & 0 deletions docs/sql/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Elasticsearch DSL directly.

SQL query:

```console
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql -d '{
"query" : "SELECT firstname, lastname, balance FROM accounts",
"filter" : {
Expand All @@ -48,9 +49,11 @@ SQL query:
}
}
}'
```

Explain:

```json
{
"from" : 0,
"size" : 200,
Expand Down Expand Up @@ -90,6 +93,7 @@ Explain:
"excludes" : [ ]
}
}
```

### Example 2

Expand All @@ -98,6 +102,7 @@ in prepared SQL query.

SQL query:

```console
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql -d '{
"query" : "SELECT * FROM accounts WHERE age = ?",
"parameters" : [
Expand All @@ -107,9 +112,11 @@ SQL query:
}
]
}'
```

Explain:

```json
{
"from" : 0,
"size" : 200,
Expand Down Expand Up @@ -138,6 +145,7 @@ Explain:
}
}
}
```

## Elasticsearch DSL

Expand All @@ -151,12 +159,15 @@ efforts are needed to parse and interpret it.

SQL query:

```console
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql -d '{
"query" : "SELECT firstname, lastname, age FROM accounts ORDER BY age LIMIT 2"
}'
```

Result set:

```json
{
"_shards" : {
"total" : 5,
Expand Down Expand Up @@ -204,6 +215,7 @@ Result set:
"took" : 100,
"timed_out" : false
}
```

## JDBC Format

Expand All @@ -220,12 +232,15 @@ and `datarows` includes the result set.

SQL query:

```console
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql?format=jdbc -d '{
"query" : "SELECT firstname, lastname, age FROM accounts ORDER BY age LIMIT 2"
}'
```

Result set:

```json
{
"schema" : [
{
Expand Down Expand Up @@ -257,6 +272,7 @@ Result set:
"size" : 2,
"status" : 200
}
```

### Example 2

Expand All @@ -265,12 +281,15 @@ instead.

SQL query:

```console
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql?format=jdbc -d '{
"query" : "SELECT unknown FROM accounts"
}'
```

Result set:

```json
{
"error" : {
"reason" : "Invalid SQL query",
Expand All @@ -279,6 +298,7 @@ Result set:
},
"status" : 400
}
```

## CSV Format

Expand All @@ -290,17 +310,21 @@ You can also use CSV format to download result set as CSV.

SQL query:

```console
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql?format=csv -d '{
"query" : "SELECT firstname, lastname, age FROM accounts ORDER BY age"
}'
```

Result set:

```csv
firstname,lastname,age
Nanette,Bates,28
Amber,Duke,32
Dale,Adams,33
Hattie,Bond,36
```

## Raw Format

Expand All @@ -313,13 +337,17 @@ line tool for post processing.

SQL query:

```console
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql?format=raw -d '{
"query" : "SELECT firstname, lastname, age FROM accounts ORDER BY age"
}'
```

Result set:

```
Nanette|Bates|28
Amber|Duke|32
Dale|Adams|33
Hattie|Bond|36
```
Loading

0 comments on commit c6a697a

Please sign in to comment.