get-field-mapping.asciidoc 5.5 KB

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