index-patterns.asciidoc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. The same kind of patterns can also be used to query multiple indices or tables.
  19. For example:
  20. ["source","sql",subs="attributes,callouts,macros"]
  21. ----
  22. include-tagged::{sql-specs}/docs.csv-spec[fromTablePatternQuoted]
  23. ----
  24. NOTE: There is the restriction that all resolved concrete tables have the exact same mapping.
  25. * SQL `LIKE` notation
  26. The common `LIKE` statement (including escaping if needed) to match a wildcard pattern, based on one `_`
  27. or multiple `%` characters.
  28. Using `SHOW TABLES` command again:
  29. ["source","sql",subs="attributes,callouts,macros"]
  30. ----
  31. include-tagged::{sql-specs}/docs.csv-spec[showTablesLikeWildcard]
  32. ----
  33. The pattern matches all tables that start with `emp`.
  34. This command supports _escaping_ as well, for example:
  35. ["source","sql",subs="attributes,callouts,macros"]
  36. ----
  37. include-tagged::{sql-specs}/docs.csv-spec[showTablesLikeEscape]
  38. ----
  39. Notice how now `emp%` does not match any tables because `%`, which means match zero or more characters,
  40. has been escaped by `!` and thus becomes an regular char. And since there is no table named `emp%`,
  41. an empty table is returned.
  42. In a nutshell, the differences between the two type of patterns are:
  43. [cols="^h,^,^"]
  44. |===
  45. s|Feature
  46. s|Multi index
  47. s|SQL `LIKE`
  48. | Type of quoting | `"` | `'`
  49. | Inclusion | Yes | Yes
  50. | Exclusion | Yes | No
  51. | Enumeration | Yes | No
  52. | One char pattern | No | `_`
  53. | Multi char pattern | `*` | `%`
  54. | Escaping | No | `ESCAPE`
  55. |===
  56. Which one to use, is up to you however try to stick to the same one across your queries for consistency.
  57. NOTE: As the query type of quoting between the two patterns is fairly similar (`"` vs `'`), {es-sql} _always_
  58. requires the keyword `LIKE` for SQL `LIKE` pattern.