get-field-mapping.asciidoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. This is useful
  7. if you don't need the <<indices-get-mapping,complete mapping>> of an index or
  8. your index contains a large number of fields.
  9. [source,console]
  10. ----
  11. GET /twitter/_mapping/field/user
  12. ----
  13. // TEST[setup:twitter]
  14. [[get-field-mapping-api-request]]
  15. ==== {api-request-title}
  16. `GET /_mapping/field/<field>`
  17. `GET /<index>/_mapping/field/<field>`
  18. [[get-field-mapping-api-path-params]]
  19. ==== {api-path-parms-title}
  20. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index]
  21. `<field>`::
  22. (Optional, string) Comma-separated list or wildcard expression of fields used to
  23. limit returned information.
  24. [[get-field-mapping-api-query-params]]
  25. ==== {api-query-parms-title}
  26. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  27. +
  28. Defaults to `true`.
  29. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  30. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  31. `include_defaults`::
  32. (Optional, boolean) If `true`, the response includes default mapping values.
  33. Defaults to `false`.
  34. [[get-field-mapping-api-example]]
  35. ==== {api-examples-title}
  36. [[get-field-mapping-api-basic-ex]]
  37. ===== Example with index setup
  38. You can provide field mappings when creating a new index. The following
  39. <<indices-create-index, create index>> API request creates the `publications`
  40. index with several field mappings.
  41. [source,console]
  42. --------------------------------------------------
  43. PUT /publications
  44. {
  45. "mappings": {
  46. "properties": {
  47. "id": { "type": "text" },
  48. "title": { "type": "text"},
  49. "abstract": { "type": "text"},
  50. "author": {
  51. "properties": {
  52. "id": { "type": "text" },
  53. "name": { "type": "text" }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. --------------------------------------------------
  60. The following returns the mapping of the field `title` only:
  61. [source,console]
  62. --------------------------------------------------
  63. GET publications/_mapping/field/title
  64. --------------------------------------------------
  65. // TEST[continued]
  66. The API returns the following response:
  67. [source,console-result]
  68. --------------------------------------------------
  69. {
  70. "publications": {
  71. "mappings": {
  72. "title": {
  73. "full_name": "title",
  74. "mapping": {
  75. "title": {
  76. "type": "text"
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. --------------------------------------------------
  84. [[get-field-mapping-api-specific-fields-ex]]
  85. ===== Specifying fields
  86. The get mapping api allows you to specify a comma-separated list of fields.
  87. For instance to select the `id` of the `author` field, you must use its full name `author.id`.
  88. [source,console]
  89. --------------------------------------------------
  90. GET publications/_mapping/field/author.id,abstract,name
  91. --------------------------------------------------
  92. // TEST[continued]
  93. returns:
  94. [source,console-result]
  95. --------------------------------------------------
  96. {
  97. "publications": {
  98. "mappings": {
  99. "author.id": {
  100. "full_name": "author.id",
  101. "mapping": {
  102. "id": {
  103. "type": "text"
  104. }
  105. }
  106. },
  107. "abstract": {
  108. "full_name": "abstract",
  109. "mapping": {
  110. "abstract": {
  111. "type": "text"
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }
  118. --------------------------------------------------
  119. The get field mapping API also supports wildcard notation.
  120. [source,console]
  121. --------------------------------------------------
  122. GET publications/_mapping/field/a*
  123. --------------------------------------------------
  124. // TEST[continued]
  125. returns:
  126. [source,console-result]
  127. --------------------------------------------------
  128. {
  129. "publications": {
  130. "mappings": {
  131. "author.name": {
  132. "full_name": "author.name",
  133. "mapping": {
  134. "name": {
  135. "type": "text"
  136. }
  137. }
  138. },
  139. "abstract": {
  140. "full_name": "abstract",
  141. "mapping": {
  142. "abstract": {
  143. "type": "text"
  144. }
  145. }
  146. },
  147. "author.id": {
  148. "full_name": "author.id",
  149. "mapping": {
  150. "id": {
  151. "type": "text"
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. --------------------------------------------------
  159. [[get-field-mapping-api-multi-index-ex]]
  160. ===== Multiple indices and fields
  161. The get field mapping API can be used to get the mapping of multiple fields from more than one index
  162. with a single call. General usage of the API follows the
  163. following syntax: `host:port/<index>/_mapping/field/<field>` where
  164. `<index>` and `<field>` can stand for comma-separated list of names or wild cards. To
  165. get mappings for all indices you can use `_all` for `<index>`. The
  166. following are some examples:
  167. [source,console]
  168. --------------------------------------------------
  169. GET /twitter,kimchy/_mapping/field/message
  170. GET /_all/_mapping/field/message,user.id
  171. GET /_all/_mapping/field/*.id
  172. --------------------------------------------------
  173. // TEST[setup:twitter]
  174. // TEST[s/^/PUT kimchy\nPUT book\n/]