indices.asciidoc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. [[sql-index-patterns-multi]]
  7. [discrete]
  8. ==== {es} multi-index
  9. The {es} notation for enumerating, including or excluding <<api-multi-index,multi-target syntax>>
  10. is supported _as long_ as it is quoted or escaped as a table identifier.
  11. For example:
  12. [source, sql]
  13. ----
  14. include-tagged::{sql-specs}/docs/docs.csv-spec[showTablesEsMultiIndex]
  15. ----
  16. Notice the pattern is surrounded by double quotes `"`. It enumerated `*` meaning all indices however
  17. it excludes (due to `-`) all indices that start with `l`.
  18. This notation is very convenient and powerful as it allows both inclusion and exclusion, depending on
  19. the target naming convention.
  20. The same kind of patterns can also be used to query multiple indices or tables.
  21. For example:
  22. [source, sql]
  23. ----
  24. include-tagged::{sql-specs}/docs/docs.csv-spec[fromTablePatternQuoted]
  25. ----
  26. NOTE: There is the restriction that all resolved concrete tables have the exact same mapping.
  27. [[sql-index-patterns-like]]
  28. [discrete]
  29. ==== SQL `LIKE` notation
  30. The common `LIKE` statement (including escaping if needed) to match a wildcard pattern, based on one `_`
  31. or multiple `%` characters.
  32. Using `SHOW TABLES` command again:
  33. [source, sql]
  34. ----
  35. include-tagged::{sql-specs}/docs/docs.csv-spec[showTablesLikeWildcard]
  36. ----
  37. The pattern matches all tables that start with `emp`.
  38. This command supports _escaping_ as well, for example:
  39. [source, sql]
  40. ----
  41. include-tagged::{sql-specs}/docs/docs.csv-spec[showTablesLikeEscape]
  42. ----
  43. Notice how now `emp%` does not match any tables because `%`, which means match zero or more characters,
  44. has been escaped by `!` and thus becomes an regular char. And since there is no table named `emp%`,
  45. an empty table is returned.
  46. In a nutshell, the differences between the two type of patterns are:
  47. [cols="^h,^,^"]
  48. |===
  49. s|Feature
  50. s|Multi index
  51. s|SQL `LIKE`
  52. | Type of quoting | `"` | `'`
  53. | Inclusion | Yes | Yes
  54. | Exclusion | Yes | No
  55. | Enumeration | Yes | No
  56. | One char pattern | No | `_`
  57. | Multi char pattern | `*` | `%`
  58. | Escaping | No | `ESCAPE`
  59. |===
  60. Which one to use, is up to you however try to stick to the same one across your queries for consistency.
  61. NOTE: As the query type of quoting between the two patterns is fairly similar (`"` vs `'`), {es-sql} _always_
  62. requires the keyword `LIKE` for SQL `LIKE` pattern.
  63. [[sql-index-frozen]]
  64. === Frozen Indices
  65. By default, {es-sql} doesn't search <<freeze-index-api,frozen indices>>. To
  66. search frozen indices, use one of the following features:
  67. dedicated configuration parameter::
  68. Set to `true` properties `index_include_frozen` in the <<sql-rest>> or `index.include.frozen` in the drivers to include frozen indices.
  69. dedicated keyword::
  70. Explicitly perform the inclusion through the dedicated `FROZEN` keyword in the `FROM` clause or `INCLUDE FROZEN` in the `SHOW` commands:
  71. [source, sql]
  72. ----
  73. include-tagged::{sql-specs}/docs/docs.csv-spec[showTablesIncludeFrozen]
  74. ----
  75. [source, sql]
  76. ----
  77. include-tagged::{sql-specs}/docs/docs.csv-spec[fromTableIncludeFrozen]
  78. ----
  79. 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.