field-caps.asciidoc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. [[search-field-caps]]
  2. === Field capabilities API
  3. ++++
  4. <titleabbrev>Field capabilities</titleabbrev>
  5. ++++
  6. Allows you to retrieve the capabilities of fields among multiple indices.
  7. For data streams, the API returns field capabilities among the stream's backing
  8. indices.
  9. [source,console]
  10. --------------------------------------------------
  11. GET /_field_caps?fields=rating
  12. --------------------------------------------------
  13. [[search-field-caps-api-request]]
  14. ==== {api-request-title}
  15. `GET /_field_caps?fields=<fields>`
  16. `POST /_field_caps?fields=<fields>`
  17. `GET /<target>/_field_caps?fields=<fields>`
  18. `POST /<target>/_field_caps?fields=<fields>`
  19. [[search-field-caps-api-prereqs]]
  20. ==== {api-prereq-title}
  21. * If the {es} {security-features} are enabled, you must have the
  22. `view_index_metadata`, `read`, or `manage` <<privileges-list-indices,index
  23. privilege>> for the target data stream, index, or index alias.
  24. [[search-field-caps-api-desc]]
  25. ==== {api-description-title}
  26. The field capabilities API returns the information about the capabilities of
  27. fields among multiple indices.
  28. The field capabilities API returns <<runtime,runtime fields>> like any
  29. other field. For example, a runtime field with a type of
  30. `keyword` is returned as any other field that belongs to the `keyword` family.
  31. [[search-field-caps-api-path-params]]
  32. ==== {api-path-parms-title}
  33. `<target>`::
  34. (Optional, string)
  35. Comma-separated list of data streams, indices, and index aliases used to limit
  36. the request. Wildcard expressions (`*`) are supported.
  37. +
  38. To target all data streams and indices in a cluster, omit this parameter or use
  39. `_all` or `*`.
  40. [[search-field-caps-api-query-params]]
  41. ==== {api-query-parms-title}
  42. `fields`::
  43. (Required, string)
  44. Comma-separated list of fields to retrieve capabilities for. Wildcard (`*`)
  45. expressions are supported.
  46. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  47. +
  48. Defaults to `true`.
  49. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  50. +
  51. --
  52. Defaults to `open`.
  53. --
  54. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  55. `include_unmapped`::
  56. (Optional, Boolean) If `true`, unmapped fields are included in the response.
  57. Defaults to `false`.
  58. [[search-field-caps-api-request-body]]
  59. ==== {api-request-body-title}
  60. `index_filter`::
  61. (Optional, <<query-dsl,query object>> Allows to filter indices if the provided
  62. query rewrites to `match_none` on every shard.
  63. [[search-field-caps-api-response-body]]
  64. ==== {api-response-body-title}
  65. The types used in the response describe _families_ of field types.
  66. Normally a type family is the same as the field type declared in the mapping,
  67. but to simplify matters certain field types that behave identically are
  68. described using a type family. For example, `keyword`, `constant_keyword` and `wildcard`
  69. field types are all described as the `keyword` type family.
  70. `searchable`::
  71. Whether this field is indexed for search on all indices.
  72. `aggregatable`::
  73. Whether this field can be aggregated on all indices.
  74. `indices`::
  75. The list of indices where this field has the same type family, or null if all indices
  76. have the same type family for the field.
  77. `non_searchable_indices`::
  78. The list of indices where this field is not searchable, or null if all indices
  79. have the same definition for the field.
  80. `non_aggregatable_indices`::
  81. The list of indices where this field is not aggregatable, or null if all
  82. indices have the same definition for the field.
  83. `meta`::
  84. Merged metadata across all indices as a map of string keys to arrays of values.
  85. A value length of 1 indicates that all indices had the same value for this key,
  86. while a length of 2 or more indicates that not all indices had the same value
  87. for this key.
  88. [[search-field-caps-api-example]]
  89. ==== {api-examples-title}
  90. The request can be restricted to specific data streams and indices:
  91. [source,console]
  92. --------------------------------------------------
  93. GET my-index-000001/_field_caps?fields=rating
  94. --------------------------------------------------
  95. // TEST[setup:my_index]
  96. The next example API call requests information about the `rating` and the
  97. `title` fields:
  98. [source,console]
  99. --------------------------------------------------
  100. GET _field_caps?fields=rating,title
  101. --------------------------------------------------
  102. The API returns the following response:
  103. [source,console-result]
  104. --------------------------------------------------
  105. {
  106. "indices": [ "index1", "index2", "index3", "index4", "index5" ],
  107. "fields": {
  108. "rating": { <1>
  109. "long": {
  110. "searchable": true,
  111. "aggregatable": false,
  112. "indices": [ "index1", "index2" ],
  113. "non_aggregatable_indices": [ "index1" ] <2>
  114. },
  115. "keyword": {
  116. "searchable": false,
  117. "aggregatable": true,
  118. "indices": [ "index3", "index4" ],
  119. "non_searchable_indices": [ "index4" ] <3>
  120. }
  121. },
  122. "title": { <4>
  123. "text": {
  124. "searchable": true,
  125. "aggregatable": false
  126. }
  127. }
  128. }
  129. }
  130. --------------------------------------------------
  131. // TESTRESPONSE[skip:historically skipped]
  132. <1> The field `rating` is defined as a long in `index1` and `index2`
  133. and as a `keyword` in `index3` and `index4`.
  134. <2> The field `rating` is not aggregatable in `index1`.
  135. <3> The field `rating` is not searchable in `index4`.
  136. <4> The field `title` is defined as `text` in all indices.
  137. By default unmapped fields are ignored. You can include them in the response by
  138. adding a parameter called `include_unmapped` in the request:
  139. [source,console]
  140. --------------------------------------------------
  141. GET _field_caps?fields=rating,title&include_unmapped
  142. --------------------------------------------------
  143. In which case the response will contain an entry for each field that is present
  144. in some indices but not all:
  145. [source,console-result]
  146. --------------------------------------------------
  147. {
  148. "indices": [ "index1", "index2", "index3" ],
  149. "fields": {
  150. "rating": {
  151. "long": {
  152. "searchable": true,
  153. "aggregatable": false,
  154. "indices": [ "index1", "index2" ],
  155. "non_aggregatable_indices": [ "index1" ]
  156. },
  157. "keyword": {
  158. "searchable": false,
  159. "aggregatable": true,
  160. "indices": [ "index3", "index4" ],
  161. "non_searchable_indices": [ "index4" ]
  162. },
  163. "unmapped": { <1>
  164. "indices": [ "index5" ],
  165. "searchable": false,
  166. "aggregatable": false
  167. }
  168. },
  169. "title": {
  170. "text": {
  171. "indices": [ "index1", "index2", "index3", "index4" ],
  172. "searchable": true,
  173. "aggregatable": false
  174. },
  175. "unmapped": { <2>
  176. "indices": [ "index5" ],
  177. "searchable": false,
  178. "aggregatable": false
  179. }
  180. }
  181. }
  182. }
  183. --------------------------------------------------
  184. // TESTRESPONSE[skip:historically skipped]
  185. <1> The `rating` field is unmapped` in `index5`.
  186. <2> The `title` field is unmapped` in `index5`.
  187. It is also possible to filter indices with a query:
  188. [source,console]
  189. --------------------------------------------------
  190. POST my-index-*/_field_caps?fields=rating
  191. {
  192. "index_filter": {
  193. "range": {
  194. "@timestamp": {
  195. "gte": "2018"
  196. }
  197. }
  198. }
  199. }
  200. --------------------------------------------------
  201. // TEST[setup:my_index]
  202. In which case indices that rewrite the provided filter to `match_none` on every shard
  203. will be filtered from the response.
  204. --
  205. [IMPORTANT]
  206. ====
  207. The filtering is done on a best-effort basis, it uses index statistics and mappings
  208. to rewrite queries to `match_none` instead of fully executing the request.
  209. For instance a `range` query over a `date` field can rewrite to `match_none`
  210. if all documents within a shard (including deleted documents) are outside
  211. of the provided range.
  212. However, not all queries can rewrite to `match_none` so this API may return
  213. an index even if the provided filter matches no document.
  214. ====
  215. --