alias.asciidoc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. [chapter]
  2. [[alias]]
  3. = Aliases
  4. An alias is a secondary name for a group of data streams or indices. Most {es}
  5. APIs accept an alias in place of a data stream or index name.
  6. You can change the data streams or indices of an alias at any time. If you use
  7. aliases in your application's {es} requests, you can reindex data with no
  8. downtime or changes to your app's code.
  9. [discrete]
  10. [[alias-types]]
  11. === Alias types
  12. There are two types of aliases:
  13. * A **data stream alias** points to one or more data streams.
  14. * An **index alias** points to one or more indices.
  15. An alias cannot point to both data streams and indices. You also cannot add a
  16. data stream's backing index to an index alias.
  17. [discrete]
  18. [[add-alias]]
  19. === Add an alias
  20. To add an existing data stream or index to an alias, use the
  21. <<indices-aliases,aliases API>>'s `add` action. If the alias doesn't exist, the
  22. request creates it.
  23. [source,console]
  24. ----
  25. POST _aliases
  26. {
  27. "actions": [
  28. {
  29. "add": {
  30. "index": "logs-nginx.access-prod",
  31. "alias": "logs"
  32. }
  33. }
  34. ]
  35. }
  36. ----
  37. // TEST[s/^/PUT _data_stream\/logs-nginx.access-prod\n/]
  38. The API's `index` and `indices` parameters support wildcards (`*`). If a
  39. wildcard pattern matches both data streams and indices, the action only uses
  40. matching data streams.
  41. [source,console]
  42. ----
  43. POST _aliases
  44. {
  45. "actions": [
  46. {
  47. "add": {
  48. "index": "logs-*",
  49. "alias": "logs"
  50. }
  51. }
  52. ]
  53. }
  54. ----
  55. // TEST[s/^/PUT _data_stream\/logs-nginx.access-prod\n/]
  56. [discrete]
  57. [[remove-alias]]
  58. === Remove an alias
  59. To remove an alias, use the aliases API's `remove` action.
  60. [source,console]
  61. ----
  62. POST _aliases
  63. {
  64. "actions": [
  65. {
  66. "remove": {
  67. "index": "logs-nginx.access-prod",
  68. "alias": "logs"
  69. }
  70. }
  71. ]
  72. }
  73. ----
  74. // TEST[continued]
  75. [discrete]
  76. [[multiple-actions]]
  77. === Multiple actions
  78. You can use the aliases API to perform multiple actions in a single atomic
  79. operation.
  80. For example, the `logs` alias points to a single data stream. The following
  81. request swaps the stream for the alias. During this swap, the `logs` alias has
  82. no downtime and never points to both streams at the same time.
  83. [source,console]
  84. ----
  85. POST _aliases
  86. {
  87. "actions": [
  88. {
  89. "remove": {
  90. "index": "logs-nginx.access-prod",
  91. "alias": "logs"
  92. }
  93. },
  94. {
  95. "add": {
  96. "index": "logs-my_app-default",
  97. "alias": "logs"
  98. }
  99. }
  100. ]
  101. }
  102. ----
  103. // TEST[s/^/PUT _data_stream\/logs-nginx.access-prod\nPUT _data_stream\/logs-my_app-default\n/]
  104. [discrete]
  105. [[add-alias-at-creation]]
  106. === Add an alias at index creation
  107. You can also use a <<indices-component-template,component>> or
  108. <<indices-put-template,index template>> to add index aliases at index creation.
  109. You cannot use a component or index template to add a data stream alias.
  110. [source,console]
  111. ----
  112. # Component template with index aliases
  113. PUT _component_template/my-aliases
  114. {
  115. "template": {
  116. "aliases": {
  117. "my-alias": {}
  118. }
  119. }
  120. }
  121. # Index template with index aliases
  122. PUT _index_template/my-index-template
  123. {
  124. "index_patterns": [
  125. "my-index-*"
  126. ],
  127. "composed_of": [
  128. "my-aliases",
  129. "my-mappings",
  130. "my-settings"
  131. ],
  132. "template": {
  133. "aliases": {
  134. "yet-another-alias": {}
  135. }
  136. }
  137. }
  138. ----
  139. // TEST[s/,\n "my-mappings",\n "my-settings"//]
  140. // TEST[teardown:data_stream_cleanup]
  141. You can also specify index aliases in <<indices-create-index,create index API>>
  142. requests.
  143. [source,console]
  144. ----
  145. # PUT <my-index-{now/d}-000001>
  146. PUT %3Cmy-index-%7Bnow%2Fd%7D-000001%3E
  147. {
  148. "aliases": {
  149. "my-alias": {}
  150. }
  151. }
  152. ----
  153. [discrete]
  154. [[view-aliases]]
  155. === View aliases
  156. To get a list of your cluster's aliases, use the <<indices-get-alias,get alias
  157. API>> with no argument.
  158. [source,console]
  159. ----
  160. GET _alias
  161. ----
  162. // TEST[s/^/PUT _data_stream\/logs-nginx.access-prod\nPUT logs-nginx.access-prod\/_alias\/logs\n/]
  163. Specify a data stream or index before `_alias` to view its aliases.
  164. [source,console]
  165. ----
  166. GET my-data-stream/_alias
  167. ----
  168. // TEST[s/^/PUT _data_stream\/logs-nginx.access-prod\nPUT logs-nginx.access-prod\/_alias\/logs\n/]
  169. // TEST[s/my-data-stream/logs-nginx.access-prod/]
  170. Specify an alias after `_alias` to view its data streams or indices.
  171. [source,console]
  172. ----
  173. GET _alias/logs
  174. ----
  175. // TEST[s/^/PUT _data_stream\/logs-nginx.access-prod\nPUT logs-nginx.access-prod\/_alias\/logs\n/]
  176. [discrete]
  177. [[write-index]]
  178. === Write index
  179. If an alias points to multiple indices, you can use `is_write_index` to specify
  180. a write index. {es} routes any write requests for the alias to this index.
  181. [source,console]
  182. ----
  183. POST _aliases
  184. {
  185. "actions": [
  186. {
  187. "add": {
  188. "index": "my-index-2099.05.06-000001",
  189. "alias": "my-alias"
  190. }
  191. },
  192. {
  193. "add": {
  194. "index": "my-index-2099.05.07-000002",
  195. "alias": "my-alias",
  196. "is_write_index": true
  197. }
  198. }
  199. ]
  200. }
  201. ----
  202. // TEST[s/^/PUT my-index-2099.05.06-000001\nPUT my-index-2099.05.07-000002\n/]
  203. TIP: We recommend using data streams to store append-only time series data. If
  204. you frequently update or delete existing time series data, use an index alias
  205. with a write index instead. See
  206. <<manage-time-series-data-without-data-streams>>.
  207. If an alias points to multiple indices with no write index, the alias rejects
  208. write requests. If an alias points to one index and `is_write_index` is not set,
  209. the index automatically acts as the write index. Data stream aliases do not
  210. support `is_write_index`.
  211. [discrete]
  212. [[filter-alias]]
  213. === Filter an alias
  214. The `filter` option uses <<query-dsl,Query DSL>> to limit the documents an alias
  215. can access. Data stream aliases do not support `filter`.
  216. [source,console]
  217. ----
  218. POST _aliases
  219. {
  220. "actions": [
  221. {
  222. "add": {
  223. "index": "my-index-2099.05.07-000002",
  224. "alias": "my-alias",
  225. "is_write_index": true,
  226. "filter": {
  227. "range": {
  228. "@timestamp": {
  229. "gte": "now-1d/d",
  230. "lt": "now/d"
  231. }
  232. }
  233. }
  234. }
  235. }
  236. ]
  237. }
  238. ----
  239. // TEST[s/^/PUT my-index-2099.05.07-000002\n/]
  240. [discrete]
  241. [[alias-routing]]
  242. === Routing
  243. Use the `routing` option to <<mapping-routing-field,route>> requests for an
  244. alias to a specific shard. This lets you take advantage of
  245. <<shard-request-cache,shard caches>> to speed up searches. Data stream aliases
  246. do not support routing options.
  247. [source,console]
  248. ----
  249. POST _aliases
  250. {
  251. "actions": [
  252. {
  253. "add": {
  254. "index": "my-index-2099.05.06-000001",
  255. "alias": "my-alias",
  256. "routing": "1"
  257. }
  258. }
  259. ]
  260. }
  261. ----
  262. // TEST[s/^/PUT my-index-2099.05.06-000001\n/]
  263. Use `index_routing` and `search_routing` to specify different routing values for
  264. indexing and search. If specified, these options overwrite the `routing` value
  265. for their respective operations.
  266. [source,console]
  267. ----
  268. POST _aliases
  269. {
  270. "actions": [
  271. {
  272. "add": {
  273. "index": "my-index-2099.05.06-000001",
  274. "alias": "my-alias",
  275. "search_routing": "1",
  276. "index_routing": "2"
  277. }
  278. }
  279. ]
  280. }
  281. ----
  282. // TEST[s/^/PUT my-index-2099.05.06-000001\n/]