get-alias.asciidoc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. [[indices-get-alias]]
  2. === Get index alias API
  3. ++++
  4. <titleabbrev>Get index alias</titleabbrev>
  5. ++++
  6. Returns information about one or more index aliases.
  7. include::{es-repo-dir}/glossary.asciidoc[tag=index-alias-desc]
  8. [source,console]
  9. ----
  10. GET /my-index-000001/_alias/alias1
  11. ----
  12. // TEST[setup:my_index]
  13. // TEST[s/^/PUT my-index-000001\/_alias\/alias1\n/]
  14. [[get-alias-api-request]]
  15. ==== {api-request-title}
  16. `GET /_alias`
  17. `GET /_alias/<alias>`
  18. `GET /<index>/_alias/<alias>`
  19. [[get-alias-api-api-prereqs]]
  20. ==== {api-prereq-title}
  21. * If the {es} {security-features} are enabled, you must have the
  22. `view_index_metadata` or `manage` <<privileges-list-indices,index privilege>>
  23. for the index alias. If you specify an index, you must also have
  24. `view_index_metadata` or `manage` index privilege for the index.
  25. [[get-alias-api-path-params]]
  26. ==== {api-path-parms-title}
  27. `<alias>`::
  28. (Optional, string)
  29. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-alias]
  30. +
  31. To retrieve information for all index aliases,
  32. use a value of `_all` or `*`.
  33. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index]
  34. [[get-alias-api-query-params]]
  35. ==== {api-query-parms-title}
  36. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  37. +
  38. Defaults to `true`.
  39. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  40. +
  41. Defaults to `all`.
  42. `ignore_unavailable`::
  43. (Optional, Boolean)
  44. If `false`, requests that include a missing index in the `<index>` argument
  45. return an error. Defaults to `false`.
  46. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=local]
  47. [[get-alias-api-example]]
  48. ==== {api-examples-title}
  49. [[get-alias-api-all-ex]]
  50. ===== Get all aliases for an index
  51. You can add index aliases during index creation
  52. using a <<indices-create-index,create index API>> request.
  53. The following create index API request creates the `logs_20302801` index
  54. with two aliases:
  55. * `current_day`
  56. * `2030`, which only returns documents
  57. in the `logs_20302801` index
  58. with a `year` field value of `2030`
  59. [source,console]
  60. --------------------------------------------------
  61. PUT /logs_20302801
  62. {
  63. "aliases" : {
  64. "current_day" : {},
  65. "2030" : {
  66. "filter" : {
  67. "term" : {"year" : 2030 }
  68. }
  69. }
  70. }
  71. }
  72. --------------------------------------------------
  73. The following get index alias API request returns all aliases
  74. for the index `logs_20302801`:
  75. [source,console]
  76. --------------------------------------------------
  77. GET /logs_20302801/_alias/*
  78. --------------------------------------------------
  79. // TEST[continued]
  80. The API returns the following response:
  81. [source,console-result]
  82. --------------------------------------------------
  83. {
  84. "logs_20302801" : {
  85. "aliases" : {
  86. "current_day" : {
  87. },
  88. "2030" : {
  89. "filter" : {
  90. "term" : {
  91. "year" : 2030
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98. --------------------------------------------------
  99. [[get-alias-api-named-ex]]
  100. ===== Get a specific alias
  101. The following index alias API request returns the `2030` alias:
  102. [source,console]
  103. --------------------------------------------------
  104. GET /_alias/2030
  105. --------------------------------------------------
  106. // TEST[continued]
  107. The API returns the following response:
  108. [source,console-result]
  109. --------------------------------------------------
  110. {
  111. "logs_20302801" : {
  112. "aliases" : {
  113. "2030" : {
  114. "filter" : {
  115. "term" : {
  116. "year" : 2030
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }
  123. --------------------------------------------------
  124. [[get-alias-api-wildcard-ex]]
  125. ===== Get aliases based on a wildcard
  126. The following index alias API request returns any alias that begin with `20`:
  127. [source,console]
  128. --------------------------------------------------
  129. GET /_alias/20*
  130. --------------------------------------------------
  131. // TEST[continued]
  132. The API returns the following response:
  133. [source,console-result]
  134. --------------------------------------------------
  135. {
  136. "logs_20302801" : {
  137. "aliases" : {
  138. "2030" : {
  139. "filter" : {
  140. "term" : {
  141. "year" : 2030
  142. }
  143. }
  144. }
  145. }
  146. }
  147. }
  148. --------------------------------------------------