get-field-mapping.asciidoc 4.2 KB

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