get-field-mapping.asciidoc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. [[indices-get-field-mapping]]
  2. == Get Field Mapping
  3. The get field mapping API allows you to retrieve mapping definitions for one or more fields.
  4. This is useful when you do not need the complete type mapping returned by
  5. the <<indices-get-mapping>> API.
  6. For example, consider the following mapping:
  7. [source,js]
  8. --------------------------------------------------
  9. PUT publications
  10. {
  11. "mappings": {
  12. "_doc": {
  13. "properties": {
  14. "id": { "type": "text" },
  15. "title": { "type": "text"},
  16. "abstract": { "type": "text"},
  17. "author": {
  18. "properties": {
  19. "id": { "type": "text" },
  20. "name": { "type": "text" }
  21. }
  22. }
  23. }
  24. }
  25. }
  26. }
  27. --------------------------------------------------
  28. // TESTSETUP
  29. // CONSOLE
  30. The following returns the mapping of the field `title` only:
  31. [source,js]
  32. --------------------------------------------------
  33. GET publications/_mapping/_doc/field/title
  34. --------------------------------------------------
  35. // CONSOLE
  36. For which the response is:
  37. [source,js]
  38. --------------------------------------------------
  39. {
  40. "publications": {
  41. "mappings": {
  42. "_doc": {
  43. "title": {
  44. "full_name": "title",
  45. "mapping": {
  46. "title": {
  47. "type": "text"
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }
  55. --------------------------------------------------
  56. // TESTRESPONSE
  57. [float]
  58. === Multiple Indices, Types and Fields
  59. The get field mapping API can be used to get the mapping of multiple fields from more than one index or type
  60. with a single call. General usage of the API follows the
  61. following syntax: `host:port/{index}/{type}/_mapping/field/{field}` where
  62. `{index}`, `{type}` and `{field}` can stand for comma-separated list of names or wild cards. To
  63. get mappings for all indices you can use `_all` for `{index}`. The
  64. following are some examples:
  65. [source,js]
  66. --------------------------------------------------
  67. GET /twitter,kimchy/_mapping/field/message
  68. GET /_all/_mapping/_doc/field/message,user.id
  69. GET /_all/_mapping/_doc/field/*.id
  70. --------------------------------------------------
  71. // CONSOLE
  72. // TEST[setup:twitter]
  73. // TEST[s/^/PUT kimchy\nPUT book\n/]
  74. [float]
  75. === Specifying fields
  76. The get mapping api allows you to specify a comma-separated list of fields.
  77. For instance to select the `id` of the `author` field, you must use its full name `author.id`.
  78. [source,js]
  79. --------------------------------------------------
  80. GET publications/_mapping/_doc/field/author.id,abstract,name
  81. --------------------------------------------------
  82. // CONSOLE
  83. returns:
  84. [source,js]
  85. --------------------------------------------------
  86. {
  87. "publications": {
  88. "mappings": {
  89. "_doc": {
  90. "author.id": {
  91. "full_name": "author.id",
  92. "mapping": {
  93. "id": {
  94. "type": "text"
  95. }
  96. }
  97. },
  98. "abstract": {
  99. "full_name": "abstract",
  100. "mapping": {
  101. "abstract": {
  102. "type": "text"
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. --------------------------------------------------
  111. // TESTRESPONSE
  112. The get field mapping API also supports wildcard notation.
  113. [source,js]
  114. --------------------------------------------------
  115. GET publications/_mapping/_doc/field/a*
  116. --------------------------------------------------
  117. // CONSOLE
  118. returns:
  119. [source,js]
  120. --------------------------------------------------
  121. {
  122. "publications": {
  123. "mappings": {
  124. "_doc": {
  125. "author.name": {
  126. "full_name": "author.name",
  127. "mapping": {
  128. "name": {
  129. "type": "text"
  130. }
  131. }
  132. },
  133. "abstract": {
  134. "full_name": "abstract",
  135. "mapping": {
  136. "abstract": {
  137. "type": "text"
  138. }
  139. }
  140. },
  141. "author.id": {
  142. "full_name": "author.id",
  143. "mapping": {
  144. "id": {
  145. "type": "text"
  146. }
  147. }
  148. }
  149. }
  150. }
  151. }
  152. }
  153. --------------------------------------------------
  154. // TESTRESPONSE
  155. [float]
  156. === Other options
  157. [horizontal]
  158. `include_defaults`::
  159. adding `include_defaults=true` to the query string will cause the response
  160. to include default values, which are normally suppressed.