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