get-alias.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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::alias-exists.asciidoc[tag=index-alias-def]
  8. [source,js]
  9. ----
  10. GET /twitter/_alias/alias1
  11. ----
  12. // CONSOLE
  13. // TEST[setup:twitter]
  14. // TEST[s/^/PUT twitter\/_alias\/alias1\n/]
  15. [[get-alias-api-request]]
  16. ==== {api-request-title}
  17. `GET /_alias`
  18. `GET /_alias/<alias>`
  19. `GET /<index>/_alias/<alias>`
  20. [[get-alias-api-path-params]]
  21. ==== {api-path-parms-title}
  22. `<alias>`::
  23. (Optional, string)
  24. include::{docdir}/rest-api/common-parms.asciidoc[tag=index-alias]
  25. +
  26. To retrieve information for all index aliases,
  27. use a value of `_all` or `*`.
  28. include::{docdir}/rest-api/common-parms.asciidoc[tag=index]
  29. [[get-alias-api-query-params]]
  30. ==== {api-query-parms-title}
  31. include::{docdir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  32. include::{docdir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  33. +
  34. Defaults to `all`.
  35. include::{docdir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  36. include::{docdir}/rest-api/common-parms.asciidoc[tag=local]
  37. [[get-alias-api-example]]
  38. ==== {api-examples-title}
  39. [[get-alias-api-all-ex]]
  40. ===== Get all aliases for an index
  41. You can add index aliases during index creation
  42. using a <<indices-create-index,create index API>> request.
  43. The following create index API request creates the `logs_20302801` index
  44. with two aliases:
  45. * `current_day`
  46. * `2030`, which only returns documents
  47. in the `logs_20302801` index
  48. with a `year` field value of `2030`
  49. [source,js]
  50. --------------------------------------------------
  51. PUT /logs_20302801
  52. {
  53. "aliases" : {
  54. "current_day" : {},
  55. "2030" : {
  56. "filter" : {
  57. "term" : {"year" : 2030 }
  58. }
  59. }
  60. }
  61. }
  62. --------------------------------------------------
  63. // CONSOLE
  64. The following get index alias API request returns all aliases
  65. for the index `logs_20302801`:
  66. [source,js]
  67. --------------------------------------------------
  68. GET /logs_20302801/_alias/*
  69. --------------------------------------------------
  70. // CONSOLE
  71. // TEST[continued]
  72. The API returns the following response:
  73. [source,console-result]
  74. --------------------------------------------------
  75. {
  76. "logs_20302801" : {
  77. "aliases" : {
  78. "current_day" : {
  79. },
  80. "2030" : {
  81. "filter" : {
  82. "term" : {
  83. "year" : 2030
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. --------------------------------------------------
  91. [[get-alias-api-named-ex]]
  92. ===== Get a specific alias
  93. The following index alias API request returns the `2030` alias:
  94. [source,js]
  95. --------------------------------------------------
  96. GET /_alias/2030
  97. --------------------------------------------------
  98. // CONSOLE
  99. // TEST[continued]
  100. The API returns the following response:
  101. [source,console-result]
  102. --------------------------------------------------
  103. {
  104. "logs_20302801" : {
  105. "aliases" : {
  106. "2030" : {
  107. "filter" : {
  108. "term" : {
  109. "year" : 2030
  110. }
  111. }
  112. }
  113. }
  114. }
  115. }
  116. --------------------------------------------------
  117. [[get-alias-api-wildcard-ex]]
  118. ===== Get aliases based on a wildcard
  119. The following index alias API request returns any alias that begin with `20`:
  120. [source,js]
  121. --------------------------------------------------
  122. GET /_alias/20*
  123. --------------------------------------------------
  124. // CONSOLE
  125. // TEST[continued]
  126. The API returns the following response:
  127. [source,console-result]
  128. --------------------------------------------------
  129. {
  130. "logs_20302801" : {
  131. "aliases" : {
  132. "2030" : {
  133. "filter" : {
  134. "term" : {
  135. "year" : 2030
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }
  142. --------------------------------------------------