get-field-mapping.asciidoc 6.4 KB

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