get-field-mapping.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. [[indices-get-field-mapping]]
  2. === Get field mapping API
  3. ++++
  4. <titleabbrev>Get field mapping</titleabbrev>
  5. ++++
  6. Retrieves <<mapping,mapping definitions>> for one or more fields. For data
  7. streams, the API retrieves field mappings for the stream's backing indices.
  8. This API is useful if you don't need a <<indices-get-mapping,complete mapping>>
  9. or if an index mapping contains a large number of fields.
  10. [source,console]
  11. ----
  12. GET /my-index-000001/_mapping/field/user
  13. ----
  14. // TEST[setup:my_index]
  15. [[get-field-mapping-api-request]]
  16. ==== {api-request-title}
  17. `GET /_mapping/field/<field>`
  18. `GET /<target>/_mapping/field/<field>`
  19. [[get-field-mapping-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 target data stream, index, or alias.
  24. [[get-field-mapping-api-path-params]]
  25. ==== {api-path-parms-title}
  26. `<target>`::
  27. (Optional, string) Comma-separated list of data streams, indices, and aliases
  28. used to limit the request. Supports wildcards (`*`). To target all data streams
  29. and indices, omit this parameter or use `*` or `_all`.
  30. `<field>`::
  31. (Optional, string) Comma-separated list or wildcard expression of fields used to
  32. limit returned information.
  33. [[get-field-mapping-api-query-params]]
  34. ==== {api-query-parms-title}
  35. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  36. +
  37. Defaults to `true`.
  38. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  39. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  40. `include_defaults`::
  41. (Optional, Boolean) If `true`, the response includes default mapping values.
  42. Defaults to `false`.
  43. [[get-field-mapping-api-example]]
  44. ==== {api-examples-title}
  45. [[get-field-mapping-api-basic-ex]]
  46. ===== Example with index setup
  47. You can provide field mappings when creating a new index. The following
  48. <<indices-create-index, create index>> API request creates the `publications`
  49. index with several field mappings.
  50. [source,console]
  51. --------------------------------------------------
  52. PUT /publications
  53. {
  54. "mappings": {
  55. "properties": {
  56. "id": { "type": "text" },
  57. "title": { "type": "text" },
  58. "abstract": { "type": "text" },
  59. "author": {
  60. "properties": {
  61. "id": { "type": "text" },
  62. "name": { "type": "text" }
  63. }
  64. }
  65. }
  66. }
  67. }
  68. --------------------------------------------------
  69. The following returns the mapping of the field `title` only:
  70. [source,console]
  71. --------------------------------------------------
  72. GET publications/_mapping/field/title
  73. --------------------------------------------------
  74. // TEST[continued]
  75. The API returns the following response:
  76. [source,console-result]
  77. --------------------------------------------------
  78. {
  79. "publications": {
  80. "mappings": {
  81. "title": {
  82. "full_name": "title",
  83. "mapping": {
  84. "title": {
  85. "type": "text"
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. --------------------------------------------------
  93. [[get-field-mapping-api-specific-fields-ex]]
  94. ===== Specifying fields
  95. The get mapping API allows you to specify a comma-separated list of fields.
  96. For instance to select the `id` of the `author` field, you must use its full name `author.id`.
  97. [source,console]
  98. --------------------------------------------------
  99. GET publications/_mapping/field/author.id,abstract,name
  100. --------------------------------------------------
  101. // TEST[continued]
  102. returns:
  103. [source,console-result]
  104. --------------------------------------------------
  105. {
  106. "publications": {
  107. "mappings": {
  108. "author.id": {
  109. "full_name": "author.id",
  110. "mapping": {
  111. "id": {
  112. "type": "text"
  113. }
  114. }
  115. },
  116. "abstract": {
  117. "full_name": "abstract",
  118. "mapping": {
  119. "abstract": {
  120. "type": "text"
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. --------------------------------------------------
  128. The get field mapping API also supports wildcard notation.
  129. [source,console]
  130. --------------------------------------------------
  131. GET publications/_mapping/field/a*
  132. --------------------------------------------------
  133. // TEST[continued]
  134. returns:
  135. [source,console-result]
  136. --------------------------------------------------
  137. {
  138. "publications": {
  139. "mappings": {
  140. "author.name": {
  141. "full_name": "author.name",
  142. "mapping": {
  143. "name": {
  144. "type": "text"
  145. }
  146. }
  147. },
  148. "abstract": {
  149. "full_name": "abstract",
  150. "mapping": {
  151. "abstract": {
  152. "type": "text"
  153. }
  154. }
  155. },
  156. "author.id": {
  157. "full_name": "author.id",
  158. "mapping": {
  159. "id": {
  160. "type": "text"
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. --------------------------------------------------
  168. [[get-field-mapping-api-multi-index-ex]]
  169. ===== Multiple targets and fields
  170. The get field mapping API can be used to get mappings for multiple fields from
  171. multiple data streams or indices with a single request.
  172. The `<target>` and `<field>` request path parameters both support
  173. comma-separated lists and wildcard expressions.
  174. You can omit the `<target>` parameter or use a value of `*` or `_all` to target
  175. all data streams and indices in a cluster.
  176. Similarly, you can omit the `<field>` parameter or use a value of `*` to
  177. retrieve mappings for all fields in the targeted data streams or indices.
  178. However, the `<field>` parameter does not support the `_all` value.
  179. For example, the following request retrieves mappings for the `message` field in
  180. any data stream or index named `my-index-000001` or `my-index-000002`.
  181. [source,console]
  182. ----
  183. GET /my-index-000001,my-index-000002/_mapping/field/message
  184. ----
  185. // TEST[setup:my_index]
  186. // TEST[s/^/PUT my-index-000002\n/]
  187. The following request retrieves mappings for the `message` and `user.id` fields
  188. in any data stream or index in the cluster.
  189. [source,console]
  190. ----
  191. GET /_all/_mapping/field/message
  192. ----
  193. // TEST[setup:my_index]
  194. The following request retrieves mappings for fields with an `id` property in any
  195. data stream or index in the cluster.
  196. [source,console]
  197. ----
  198. GET /_all/_mapping/field/*.id
  199. ----
  200. // TEST[setup:my_index]