2018-09-04 09:54:10 -04:00
|
|
|
[role="xpack"]
|
|
|
|
[testenv="basic"]
|
2018-09-04 12:05:21 -04:00
|
|
|
[[sql-index-patterns]]
|
2019-06-11 05:04:00 -04:00
|
|
|
=== Index patterns
|
2018-09-04 09:54:10 -04:00
|
|
|
|
|
|
|
{es-sql} supports two types of patterns for matching multiple indices or tables:
|
|
|
|
|
2019-05-10 07:19:26 -04:00
|
|
|
[[sql-index-patterns-multi]]
|
|
|
|
[float]
|
2019-06-11 05:04:00 -04:00
|
|
|
==== {es} multi-index
|
2018-09-04 09:54:10 -04:00
|
|
|
|
2020-06-30 17:33:35 -04:00
|
|
|
The {es} notation for enumerating, including or excluding <<multi-index,multi-target syntax>>
|
2018-09-04 09:54:10 -04:00
|
|
|
is supported _as long_ as it is quoted or escaped as a table identifier.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2019-05-31 13:03:41 -04:00
|
|
|
[source, sql]
|
2018-09-04 09:54:10 -04:00
|
|
|
----
|
2019-03-25 09:22:59 -04:00
|
|
|
include-tagged::{sql-specs}/docs/docs.csv-spec[showTablesEsMultiIndex]
|
2018-09-04 09:54:10 -04:00
|
|
|
----
|
|
|
|
|
|
|
|
Notice the pattern is surrounded by double quotes `"`. It enumerated `*` meaning all indices however
|
|
|
|
it excludes (due to `-`) all indices that start with `l`.
|
|
|
|
This notation is very convenient and powerful as it allows both inclusion and exclusion, depending on
|
|
|
|
the target naming convention.
|
|
|
|
|
2018-10-02 04:47:42 -04:00
|
|
|
The same kind of patterns can also be used to query multiple indices or tables.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2019-05-31 13:03:41 -04:00
|
|
|
[source, sql]
|
2018-10-02 04:47:42 -04:00
|
|
|
----
|
2019-03-25 09:22:59 -04:00
|
|
|
include-tagged::{sql-specs}/docs/docs.csv-spec[fromTablePatternQuoted]
|
2018-10-02 04:47:42 -04:00
|
|
|
----
|
|
|
|
|
|
|
|
NOTE: There is the restriction that all resolved concrete tables have the exact same mapping.
|
|
|
|
|
2019-05-10 07:19:26 -04:00
|
|
|
[[sql-index-patterns-like]]
|
|
|
|
[float]
|
2019-06-11 05:04:00 -04:00
|
|
|
==== SQL `LIKE` notation
|
2018-09-04 09:54:10 -04:00
|
|
|
|
|
|
|
The common `LIKE` statement (including escaping if needed) to match a wildcard pattern, based on one `_`
|
|
|
|
or multiple `%` characters.
|
|
|
|
|
|
|
|
Using `SHOW TABLES` command again:
|
|
|
|
|
2019-05-31 13:03:41 -04:00
|
|
|
[source, sql]
|
2018-09-04 09:54:10 -04:00
|
|
|
----
|
2019-03-25 09:22:59 -04:00
|
|
|
include-tagged::{sql-specs}/docs/docs.csv-spec[showTablesLikeWildcard]
|
2018-09-04 09:54:10 -04:00
|
|
|
----
|
|
|
|
|
|
|
|
The pattern matches all tables that start with `emp`.
|
|
|
|
|
|
|
|
This command supports _escaping_ as well, for example:
|
|
|
|
|
2019-05-31 13:03:41 -04:00
|
|
|
[source, sql]
|
2018-09-04 09:54:10 -04:00
|
|
|
----
|
2019-03-25 09:22:59 -04:00
|
|
|
include-tagged::{sql-specs}/docs/docs.csv-spec[showTablesLikeEscape]
|
2018-09-04 09:54:10 -04:00
|
|
|
----
|
|
|
|
|
|
|
|
Notice how now `emp%` does not match any tables because `%`, which means match zero or more characters,
|
|
|
|
has been escaped by `!` and thus becomes an regular char. And since there is no table named `emp%`,
|
|
|
|
an empty table is returned.
|
|
|
|
|
|
|
|
In a nutshell, the differences between the two type of patterns are:
|
|
|
|
|
2018-12-21 16:25:54 -05:00
|
|
|
[cols="^h,^,^"]
|
2018-09-04 09:54:10 -04:00
|
|
|
|===
|
2018-12-21 16:25:54 -05:00
|
|
|
s|Feature
|
|
|
|
s|Multi index
|
|
|
|
s|SQL `LIKE`
|
2018-09-04 09:54:10 -04:00
|
|
|
|
|
|
|
| Type of quoting | `"` | `'`
|
|
|
|
| Inclusion | Yes | Yes
|
|
|
|
| Exclusion | Yes | No
|
|
|
|
| Enumeration | Yes | No
|
|
|
|
| One char pattern | No | `_`
|
|
|
|
| Multi char pattern | `*` | `%`
|
|
|
|
| Escaping | No | `ESCAPE`
|
|
|
|
|
|
|
|
|===
|
|
|
|
|
|
|
|
Which one to use, is up to you however try to stick to the same one across your queries for consistency.
|
|
|
|
|
|
|
|
NOTE: As the query type of quoting between the two patterns is fairly similar (`"` vs `'`), {es-sql} _always_
|
|
|
|
requires the keyword `LIKE` for SQL `LIKE` pattern.
|
|
|
|
|
2019-05-10 07:19:26 -04:00
|
|
|
[[sql-index-frozen]]
|
2019-06-11 05:04:00 -04:00
|
|
|
=== Frozen Indices
|
2019-05-10 07:19:26 -04:00
|
|
|
|
|
|
|
{es} <<frozen-indices, frozen indices>> are a useful and powerful tool for hot/warm architecture introduced in {es} 6.6,
|
|
|
|
essentially by trading speed for memory.
|
|
|
|
{es-sql} supports frozen indices and similar to {es}, due to their performance characteristics, allows searches on them only
|
|
|
|
when explicitly told so by user - in other words, by default, frozen indices are not included in searches.
|
|
|
|
|
|
|
|
One can toggle the use of frozen indices through:
|
|
|
|
|
|
|
|
dedicated configuration parameter::
|
|
|
|
Set to `true` properties `index_include_frozen` in the <<sql-rest>> or `index.include.frozen` in the drivers to include frozen indices.
|
|
|
|
|
|
|
|
dedicated keyword::
|
|
|
|
Explicitly perform the inclusion through the dedicated `FROZEN` keyword in the `FROM` clause or `INCLUDE FROZEN` in the `SHOW` commands:
|
|
|
|
|
2019-05-31 13:03:41 -04:00
|
|
|
[source, sql]
|
2019-05-10 07:19:26 -04:00
|
|
|
----
|
|
|
|
include-tagged::{sql-specs}/docs/docs.csv-spec[showTablesIncludeFrozen]
|
|
|
|
----
|
|
|
|
|
|
|
|
|
2019-05-31 13:03:41 -04:00
|
|
|
[source, sql]
|
2019-05-10 07:19:26 -04:00
|
|
|
----
|
|
|
|
include-tagged::{sql-specs}/docs/docs.csv-spec[fromTableIncludeFrozen]
|
|
|
|
----
|
|
|
|
|
|
|
|
Unless enabled, frozen indices are completely ignored; it is as if they do not exist and as such, queries ran against them are likely to fail.
|