get-field-mapping.asciidoc 6.1 KB

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