indices.asciidoc 3.7 KB

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