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

Commit 510d596

Browse files
authored
Merge pull request #146 from dai-chen/sql-plugin-basic-usage-docs
SQL plugin docs for basic usage
2 parents b28ba08 + c6a697a commit 510d596

File tree

4 files changed

+830
-0
lines changed

4 files changed

+830
-0
lines changed

docs/sql/endpoints.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
layout: default
3+
title: Endpoints
4+
parent: SQL
5+
nav_order: 4
6+
---
7+
8+
9+
# Endpoints
10+
11+
---
12+
13+
#### Table of contents
14+
- TOC
15+
{:toc}
16+
17+
18+
---
19+
20+
## Introduction
21+
22+
To send query request to SQL plugin, you can either use a request
23+
parameter in HTTP GET or request body by HTTP POST request. POST request
24+
is recommended because it doesn't have length limitation and allows for
25+
other parameters passed to plugin for other functionality such as
26+
prepared statement. And also the explain endpoint is used very often for
27+
query translation and troubleshooting.
28+
29+
## GET
30+
31+
### Description
32+
33+
You can send HTTP GET request with your query embedded in URL parameter.
34+
35+
### Example
36+
37+
SQL query:
38+
39+
```console
40+
>> curl -H 'Content-Type: application/json' -X GET localhost:9200/_opendistro/_sql?sql=SELECT * FROM accounts
41+
```
42+
43+
## POST
44+
45+
### Description
46+
47+
You can also send HTTP POST request with your query in request body.
48+
49+
### Example
50+
51+
SQL query:
52+
53+
```console
54+
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql -d '{
55+
"query" : "SELECT * FROM accounts"
56+
}'
57+
```
58+
59+
## Explain
60+
61+
### Description
62+
63+
To translate your query, send it to explain endpoint. The explain output
64+
is Elasticsearch domain specific language (DSL) in JSON format. You can
65+
just copy and paste it to your console to run it against Elasticsearch
66+
directly.
67+
68+
### Example
69+
70+
Explain query:
71+
72+
```console
73+
>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql/_explain -d '{
74+
"query" : "SELECT firstname, lastname FROM accounts WHERE age > 20"
75+
}'
76+
```
77+
78+
Explain:
79+
80+
```json
81+
{
82+
"from" : 0,
83+
"size" : 200,
84+
"query" : {
85+
"bool" : {
86+
"filter" : [
87+
{
88+
"bool" : {
89+
"must" : [
90+
{
91+
"range" : {
92+
"age" : {
93+
"from" : 20,
94+
"to" : null,
95+
"include_lower" : false,
96+
"include_upper" : true,
97+
"boost" : 1.0
98+
}
99+
}
100+
}
101+
],
102+
"adjust_pure_negative" : true,
103+
"boost" : 1.0
104+
}
105+
}
106+
],
107+
"adjust_pure_negative" : true,
108+
"boost" : 1.0
109+
}
110+
},
111+
"_source" : {
112+
"includes" : [
113+
"firstname",
114+
"lastname"
115+
],
116+
"excludes" : [ ]
117+
}
118+
}
119+
```

docs/sql/monitoring.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
layout: default
3+
title: Plugin Monitoring
4+
parent: SQL
5+
nav_order: 7
6+
---
7+
8+
# Plugin Monitoring
9+
10+
---
11+
12+
#### Table of contents
13+
- TOC
14+
{:toc}
15+
16+
17+
---
18+
19+
## Introduction
20+
21+
By a stats endpoint, you are able to collect metrics for the plugin
22+
within the interval. Note that only node level statistics collecting is
23+
implemented for now. In other words, you only get the metrics for the
24+
node you're accessing. Cluster level statistics have yet to be
25+
implemented.
26+
27+
## Node Stats
28+
29+
### Description
30+
31+
The meaning of fields in the response is as follows:
32+
33+
| Field name| Description|
34+
| ------------------------- | ------------------------------------------------------------- |
35+
| request_total| Total count of request|
36+
| request_count| Total count of request within the interval|
37+
|failed_request_count_syserr|Count of failed request due to system error within the interval|
38+
|failed_request_count_cuserr| Count of failed request due to bad request within the interval|
39+
| failed_request_count_cb| Indicate if plugin is being circuit broken within the interval|
40+
41+
42+
### Example
43+
44+
SQL query:
45+
46+
```console
47+
>> curl -H 'Content-Type: application/json' -X GET localhost:9200/_opendistro/_sql/stats
48+
```
49+
50+
Result set:
51+
52+
```json
53+
{
54+
"failed_request_count_cb" : 0,
55+
"failed_request_count_cuserr" : 0,
56+
"circuit_breaker" : 0,
57+
"request_total" : 0,
58+
"request_count" : 0,
59+
"failed_request_count_syserr" : 0
60+
}
61+
```

0 commit comments

Comments
 (0)