index-patterns.asciidoc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-index-patterns]]
  4. == Index patterns
  5. {es-sql} supports two types of patterns for matching multiple indices or tables:
  6. * {es} multi-index
  7. The {es} notation for enumerating, including or excluding <<multi-index,multi index syntax>>
  8. is supported _as long_ as it is quoted or escaped as a table identifier.
  9. For example:
  10. ["source","sql",subs="attributes,callouts,macros"]
  11. ----
  12. include-tagged::{sql-specs}/docs.csv-spec[showTablesEsMultiIndex]
  13. ----
  14. Notice the pattern is surrounded by double quotes `"`. It enumerated `*` meaning all indices however
  15. it excludes (due to `-`) all indices that start with `l`.
  16. This notation is very convenient and powerful as it allows both inclusion and exclusion, depending on
  17. the target naming convention.
  18. * SQL `LIKE` notation
  19. The common `LIKE` statement (including escaping if needed) to match a wildcard pattern, based on one `_`
  20. or multiple `%` characters.
  21. Using `SHOW TABLES` command again:
  22. ["source","sql",subs="attributes,callouts,macros"]
  23. ----
  24. include-tagged::{sql-specs}/docs.csv-spec[showTablesLikeWildcard]
  25. ----
  26. The pattern matches all tables that start with `emp`.
  27. This command supports _escaping_ as well, for example:
  28. ["source","sql",subs="attributes,callouts,macros"]
  29. ----
  30. include-tagged::{sql-specs}/docs.csv-spec[showTablesLikeEscape]
  31. ----
  32. Notice how now `emp%` does not match any tables because `%`, which means match zero or more characters,
  33. has been escaped by `!` and thus becomes an regular char. And since there is no table named `emp%`,
  34. an empty table is returned.
  35. In a nutshell, the differences between the two type of patterns are:
  36. [cols="^h,^,^",options="header"]
  37. |===
  38. | Feature | Multi index | SQL `LIKE`
  39. | Type of quoting | `"` | `'`
  40. | Inclusion | Yes | Yes
  41. | Exclusion | Yes | No
  42. | Enumeration | Yes | No
  43. | One char pattern | No | `_`
  44. | Multi char pattern | `*` | `%`
  45. | Escaping | No | `ESCAPE`
  46. |===
  47. Which one to use, is up to you however try to stick to the same one across your queries for consistency.
  48. NOTE: As the query type of quoting between the two patterns is fairly similar (`"` vs `'`), {es-sql} _always_
  49. requires the keyword `LIKE` for SQL `LIKE` pattern.