get-field-mapping.asciidoc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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::{docdir}/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::{docdir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  27. +
  28. Defaults to `true`.
  29. include::{docdir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  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,console]
  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. The following returns the mapping of the field `title` only:
  62. [source,console]
  63. --------------------------------------------------
  64. GET publications/_mapping/field/title
  65. --------------------------------------------------
  66. // TEST[continued]
  67. The API returns the following response:
  68. [source,console-result]
  69. --------------------------------------------------
  70. {
  71. "publications": {
  72. "mappings": {
  73. "title": {
  74. "full_name": "title",
  75. "mapping": {
  76. "title": {
  77. "type": "text"
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. --------------------------------------------------
  85. [[get-field-mapping-api-specific-fields-ex]]
  86. ===== Specifying fields
  87. The get mapping api allows you to specify a comma-separated list of fields.
  88. For instance to select the `id` of the `author` field, you must use its full name `author.id`.
  89. [source,console]
  90. --------------------------------------------------
  91. GET publications/_mapping/field/author.id,abstract,name
  92. --------------------------------------------------
  93. // TEST[continued]
  94. returns:
  95. [source,console-result]
  96. --------------------------------------------------
  97. {
  98. "publications": {
  99. "mappings": {
  100. "author.id": {
  101. "full_name": "author.id",
  102. "mapping": {
  103. "id": {
  104. "type": "text"
  105. }
  106. }
  107. },
  108. "abstract": {
  109. "full_name": "abstract",
  110. "mapping": {
  111. "abstract": {
  112. "type": "text"
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. --------------------------------------------------
  120. The get field mapping API also supports wildcard notation.
  121. [source,console]
  122. --------------------------------------------------
  123. GET publications/_mapping/field/a*
  124. --------------------------------------------------
  125. // TEST[continued]
  126. returns:
  127. [source,console-result]
  128. --------------------------------------------------
  129. {
  130. "publications": {
  131. "mappings": {
  132. "author.name": {
  133. "full_name": "author.name",
  134. "mapping": {
  135. "name": {
  136. "type": "text"
  137. }
  138. }
  139. },
  140. "abstract": {
  141. "full_name": "abstract",
  142. "mapping": {
  143. "abstract": {
  144. "type": "text"
  145. }
  146. }
  147. },
  148. "author.id": {
  149. "full_name": "author.id",
  150. "mapping": {
  151. "id": {
  152. "type": "text"
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. --------------------------------------------------
  160. [[get-field-mapping-api-multi-index-ex]]
  161. ===== Multiple indices and fields
  162. The get field mapping API can be used to get the mapping of multiple fields from more than one index
  163. with a single call. General usage of the API follows the
  164. following syntax: `host:port/<index>/_mapping/field/<field>` where
  165. `<index>` and `<field>` can stand for comma-separated list of names or wild cards. To
  166. get mappings for all indices you can use `_all` for `<index>`. The
  167. following are some examples:
  168. [source,console]
  169. --------------------------------------------------
  170. GET /twitter,kimchy/_mapping/field/message
  171. GET /_all/_mapping/field/message,user.id
  172. GET /_all/_mapping/field/*.id
  173. --------------------------------------------------
  174. // TEST[setup:twitter]
  175. // TEST[s/^/PUT kimchy\nPUT book\n/]