Skip to content

Commit cdaa3c2

Browse files
clean up and add a missing file for sql jdbc
1 parent 4e0718f commit cdaa3c2

File tree

7 files changed

+95
-10
lines changed

7 files changed

+95
-10
lines changed

docs/reference/query-languages/sql/sql-concepts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This documentation while trying to be complete, does assume the reader has *basi
1919
::::
2020

2121

22-
As a general rule, Elasticsearch SQL as the name indicates provides a SQL interface to {{es}}. As such, it follows the SQL terminology and conventions first, whenever possible. However the backing engine itself is {{es}} for which Elasticsearch SQL was purposely created hence why features or concepts that are not available, or cannot be mapped correctly, in SQL appear in Elasticsearch SQL. Last but not least, Elasticsearch SQL tries to obey the [principle of least surprise](https://en.wikipedia.org/wiki/Principle_of_least_astonishment), though as all things in the world, everything is relative.
22+
As a general rule, {{es}} SQL as the name indicates provides a SQL interface to {{es}}. As such, it follows the SQL terminology and conventions first, whenever possible. However, the backing engine itself is {{es}} for which Elasticsearch SQL was purposely created hence why features or concepts that are not available, or cannot be mapped correctly, in SQL appear in Elasticsearch SQL. Last but not least, {{es}} SQL tries to obey the [principle of least surprise](https://en.wikipedia.org/wiki/Principle_of_least_astonishment), though as all things in the world, everything is relative.
2323

2424
## Mapping concepts across SQL and Elasticsearch [_mapping_concepts_across_sql_and_es]
2525

@@ -29,7 +29,7 @@ So let’s start from the bottom; these roughly are:
2929

3030
| SQL | {{es}} | Description |
3131
| --- | --- | --- |
32-
| `column` | `field` | In both cases, at the lowest level, data is stored in *named* entries, of a variety of [data types](elasticsearch://reference/query-languages/sql/sql-data-types.md), containing *one* value. SQL calls such an entry a *column* while {{es}} a *field*. Notice that in {{es}} a field can contain *multiple* values of the same type (essentially a list) while in SQL, a *column* can contain *exactly* one value of said type. Elasticsearch SQL will do its best to preserve the SQL semantic and, depending on the query, reject those that return fields with more than one value. |
32+
| `column` | `field` | In both cases, at the lowest level, data is stored in *named* entries, of a variety of [data types](sql-data-types.md), containing *one* value. SQL calls such an entry a *column* while {{es}} a *field*. Notice that in {{es}} a field can contain *multiple* values of the same type (essentially a list) while in SQL, a *column* can contain *exactly* one value of said type. Elasticsearch SQL will do its best to preserve the SQL semantic and, depending on the query, reject those that return fields with more than one value. |
3333
| `row` | `document` | `Column`s and `field`s do *not* exist by themselves; they are part of a `row` or a `document`. The two have slightly different semantics: a `row` tends to be *strict* (and have more enforcements) while a `document` tends to be a bit more flexible or loose (while still having a structure). |
3434
| `table` | `index` | The target against which queries, whether in SQL or {{es}} get executed against. |
3535
| `schema` | *implicit* | In RDBMS, `schema` is mainly a namespace of tables and typically used as a security boundary. {{es}} does not provide an equivalent concept for it. However when security is enabled, {{es}} automatically applies the security enforcement so that a role sees only the data it is allowed to (in SQL jargon, its *schema*). |

docs/reference/query-languages/sql/sql-getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ products:
1111

1212
# Getting started with SQL [sql-getting-started]
1313

14-
To start using Elasticsearch SQL, create an index with some data to experiment with:
14+
To start using {{es}} SQL, create an index with some data to experiment with:
1515

1616
```console
1717
PUT /library/_bulk?refresh
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/elasticsearch/reference/current/_api_usage.html
4+
applies_to:
5+
stack: ga
6+
serverless: ga
7+
products:
8+
- id: elasticsearch
9+
---
10+
11+
# API usage [_api_usage]
12+
13+
One can use JDBC through the official `java.sql` and `javax.sql` packages:
14+
15+
## `java.sql` [java-sql]
16+
17+
The former through `java.sql.Driver` and `DriverManager`:
18+
19+
```java
20+
String address = "jdbc:es://" + elasticsearchAddress; <1>
21+
Properties connectionProperties = connectionProperties(); <2>
22+
Connection connection =
23+
DriverManager.getConnection(address, connectionProperties);
24+
```
25+
26+
1. The server and port on which Elasticsearch is listening for HTTP traffic. The port is by default 9200.
27+
2. Properties for connecting to Elasticsearch. An empty `Properties` instance is fine for unsecured Elasticsearch.
28+
29+
30+
31+
## `javax.sql` [javax-sql]
32+
33+
Accessible through the `javax.sql.DataSource` API:
34+
35+
```java
36+
EsDataSource dataSource = new EsDataSource();
37+
String address = "jdbc:es://" + elasticsearchAddress; <1>
38+
dataSource.setUrl(address);
39+
Properties connectionProperties = connectionProperties(); <2>
40+
dataSource.setProperties(connectionProperties);
41+
Connection connection = dataSource.getConnection();
42+
```
43+
44+
1. The server and port on which Elasticsearch is listening for HTTP traffic. By default 9200.
45+
2. Properties for connecting to Elasticsearch. An empty `Properties` instance is fine for unsecured Elasticsearch.
46+
47+
48+
Which one to use? Typically client applications that provide most configuration properties in the URL rely on the `DriverManager`-style while `DataSource` is preferred when being *passed* around since it can be configured in one place and the consumer only has to call `getConnection` without having to worry about any other properties.
49+
50+
To connect to a secured Elasticsearch server the `Properties` should look like:
51+
52+
```java
53+
Properties properties = new Properties();
54+
properties.put("user", "test_admin");
55+
properties.put("password", "x-pack-test-password");
56+
```
57+
58+
Once you have the connection you can use it like any other JDBC connection. For example:
59+
60+
```java
61+
try (Statement statement = connection.createStatement();
62+
ResultSet results = statement.executeQuery(
63+
" SELECT name, page_count"
64+
+ " FROM library"
65+
+ " ORDER BY page_count DESC"
66+
+ " LIMIT 1")) {
67+
assertTrue(results.next());
68+
assertEquals("Don Quixote", results.getString(1));
69+
assertEquals(1072, results.getInt(2));
70+
SQLException e = expectThrows(SQLException.class, () ->
71+
results.getInt(1));
72+
assertThat(e.getMessage(), containsString("Unable to convert "
73+
+ "value [Don Quixote] of type [TEXT] to [Integer]"));
74+
assertFalse(results.next());
75+
}
76+
```
77+
78+
::::{note}
79+
Elasticsearch SQL doesn’t provide a connection pooling mechanism, thus the connections the JDBC driver creates are not pooled. In order to achieve pooled connections, a third-party connection pooling mechanism is required. Configuring and setting up the third-party provider is outside the scope of this documentation.
80+
::::
81+
82+
83+

docs/reference/query-languages/sql/sql-jdbc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ products:
1010

1111
# SQL JDBC [sql-jdbc]
1212

13-
{{es}}'s SQL jdbc driver is a rich, fully featured JDBC driver for {{es}}. It is Type 4 driver, meaning it is a platform independent, stand-alone, Direct to Database, pure Java driver that converts JDBC calls to Elasticsearch SQL.
13+
{{es}}'s SQL jdbc driver is a rich, fully featured JDBC driver for {{es}}. It is Type 4 driver, meaning it is a platform independent, stand-alone, Direct to Database, pure Java driver that converts JDBC calls to {{es}} SQL.
1414

1515

1616
## Installation [sql-jdbc-installation]

docs/reference/query-languages/sql/sql-odbc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ products:
1212

1313
## Overview [sql-odbc-overview]
1414

15-
Elasticsearch SQL ODBC Driver is a 3.80 compliant ODBC driver for {{es}}. It is a core level driver, exposing all of the functionality accessible through the {{es}}'s SQL API, converting ODBC calls into Elasticsearch SQL.
15+
{{es}} SQL ODBC Driver is a 3.80 compliant ODBC driver for {{es}}. It is a core level driver, exposing all the functionality accessible through the {{es}}'s SQL API, converting ODBC calls into {{es}} SQL.
1616

17-
In order to make use of the driver, the server must have Elasticsearch SQL installed and running with the valid license.
17+
In order to make use of the driver, the server must have {{es}} SQL installed and running with the valid license.
1818

1919
* [Driver installation](sql-odbc-installation.md)
2020
* [Configuration](sql-odbc-setup.md)

docs/reference/query-languages/sql/sql-security.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ products:
1010

1111
# Security [sql-security]
1212

13-
Elasticsearch SQL integrates with security, if this is enabled on your cluster. In such a scenario, Elasticsearch SQL supports both security at the transport layer (by encrypting the communication between the consumer and the server) and authentication (for the access layer).
13+
{{es}} SQL integrates with security, if this is enabled on your cluster. In such a scenario, {{es}} SQL supports both security at the transport layer (by encrypting the communication between the consumer and the server) and authentication (for the access layer).
1414

1515

1616
## SSL/TLS configuration [ssl-tls-config]
1717

18-
In case of an encrypted transport, the SSL/TLS support needs to be enabled in Elasticsearch SQL to properly establish communication with {{es}}. This is done by setting the `ssl` property to `true` or by using the `https` prefix in the URL.<br> Depending on your SSL configuration (whether the certificates are signed by a CA or not, whether they are global at JVM level or just local to one application), might require setting up the `keystore` and/or `truststore`, that is where the *credentials* are stored (`keystore` - which typically stores private keys and certificates) and how to *verify* them (`truststore` - which typically stores certificates from third party also known as CA - certificate authorities).<br> Typically (and again, do note that your environment might differ significantly), if the SSL setup for Elasticsearch SQL is not already done at the JVM level, one needs to setup the keystore if the Elasticsearch SQL security requires client authentication (PKI - Public Key Infrastructure), and setup `truststore` if SSL is enabled.
18+
In case of an encrypted transport, the SSL/TLS support needs to be enabled in Elasticsearch SQL to properly establish communication with {{es}}. This is done by setting the `ssl` property to `true` or by using the `https` prefix in the URL.<br> Depending on your SSL configuration (whether the certificates are signed by a CA or not, whether they are global at JVM level or just local to one application), might require setting up the `keystore` and/or `truststore`, that is where the *credentials* are stored (`keystore` - which typically stores private keys and certificates) and how to *verify* them (`truststore` - which typically stores certificates from third party also known as CA - certificate authorities).<br> Typically (and again, do note that your environment might differ significantly), if the SSL setup for {{es}} SQL is not already done at the JVM level, one needs to setup the keystore if the Elasticsearch SQL security requires client authentication (PKI - Public Key Infrastructure), and setup `truststore` if SSL is enabled.
1919

2020

2121
## Authentication [_authentication]
2222

23-
The authentication support in Elasticsearch SQL is of two types:
23+
The authentication support in {{es}} SQL is of two types:
2424

2525
Username/Password
2626
: Set these through `user` and `password` properties.
2727

2828
PKI/X.509
29-
: Use X.509 certificates to authenticate Elasticsearch SQL to {{es}}. For this, one would need to setup the `keystore` containing the private key and certificate to the appropriate user (configured in {{es}}) and the `truststore` with the CA certificate used to sign the SSL/TLS certificates in the {{es}} cluster. That is, one should setup the key to authenticate Elasticsearch SQL and also to verify that is the right one. To do so, one should set the `ssl.keystore.location` and `ssl.truststore.location` properties to indicate the `keystore` and `truststore` to use. It is recommended to have these secured through a password in which case `ssl.keystore.pass` and `ssl.truststore.pass` properties are required.
29+
: Use X.509 certificates to authenticate {{es}} SQL to {{es}}. For this, one would need to setup the `keystore` containing the private key and certificate to the appropriate user (configured in {{es}}) and the `truststore` with the CA certificate used to sign the SSL/TLS certificates in the {{es}} cluster. That is, one should setup the key to authenticate {{es}} SQL and also to verify that is the right one. To do so, one should set the `ssl.keystore.location` and `ssl.truststore.location` properties to indicate the `keystore` and `truststore` to use. It is recommended to have these secured through a password in which case `ssl.keystore.pass` and `ssl.truststore.pass` properties are required.
3030

3131

3232
## Permissions (server-side) [sql-security-permissions]

docs/reference/query-languages/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ toc:
176176
- file: sql/sql-translate.md
177177
- file: sql/sql-cli.md
178178
- file: sql/sql-jdbc.md
179+
children:
180+
- file: sql/sql-jdbc-api-usage.md
179181
- file: sql/sql-odbc.md
180182
children:
181183
- file: sql/sql-odbc-installation.md

0 commit comments

Comments
 (0)