field-caps.asciidoc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 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) Comma-separated list of data streams, indices, and aliases
  35. used to limit the request. Supports wildcards (`*`). To target all data streams
  36. and indices, omit this parameter or use `*` or `_all`.
  37. [[search-field-caps-api-query-params]]
  38. ==== {api-query-parms-title}
  39. `fields`::
  40. (Required, string)
  41. Comma-separated list of fields to retrieve capabilities for. Wildcard (`*`)
  42. expressions are supported.
  43. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  44. +
  45. Defaults to `true`.
  46. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  47. +
  48. --
  49. Defaults to `open`.
  50. --
  51. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  52. `include_unmapped`::
  53. (Optional, Boolean) If `true`, unmapped fields are included in the response.
  54. Defaults to `false`.
  55. `filters`::
  56. (Optional, string) Comma-separated list of filters to apply to the response.
  57. +
  58. .Valid values for `filters`
  59. [%collapsible%open]
  60. ====
  61. `+metadata`::
  62. Only include metadata fields
  63. `-metadata`::
  64. Exclude metadata fields
  65. `-parent`::
  66. Exclude parent fields
  67. `-nested`::
  68. Exclude nested fields
  69. `-multifield`::
  70. Exclude multifields
  71. ====
  72. `types`::
  73. (Optional, string) Comma-separated list of field types to include. Any fields that
  74. do not match one of these types will be excluded from the results. Defaults to empty,
  75. meaning that all field types are returned. See <<field-caps-field-types,here>> for
  76. more information about field types in field capabilities requests and responses.
  77. [[search-field-caps-api-request-body]]
  78. ==== {api-request-body-title}
  79. `index_filter`::
  80. (Optional, <<query-dsl,query object>> Allows to filter indices if the provided
  81. query rewrites to `match_none` on every shard.
  82. `runtime_mappings`::
  83. (Optional, object)
  84. Defines ad-hoc <<runtime-search-request,runtime fields>> in the request similar
  85. to the way it is done in <<search-api-body-runtime, search requests>>. These fields
  86. exist only as part of the query and take precedence over fields defined with the
  87. same name in the index mappings.
  88. [[search-field-caps-api-response-body]]
  89. ==== {api-response-body-title}
  90. [[field-caps-field-types]]
  91. The types used in the response describe _families_ of field types.
  92. Normally a type family is the same as the field type declared in the mapping,
  93. but to simplify matters certain field types that behave identically are
  94. described using a type family. For example, `keyword`, `constant_keyword` and `wildcard`
  95. field types are all described as the `keyword` type family.
  96. `metadata_field`::
  97. Whether this field is registered as a <<mapping-fields,metadata field>>.
  98. `searchable`::
  99. Whether this field is indexed for search on all indices.
  100. `aggregatable`::
  101. Whether this field can be aggregated on all indices.
  102. `time_series_dimension`::
  103. preview:[]
  104. Whether this field is used as a time series dimension.
  105. `time_series_metric`::
  106. preview:[]
  107. Contains metric type if this fields is used as a time series metrics, absent if the field is not used as metric.
  108. `indices`::
  109. The list of indices where this field has the same type family, or null if all indices
  110. have the same type family for the field.
  111. `non_searchable_indices`::
  112. The list of indices where this field is not searchable, or null if all indices
  113. have the same definition for the field.
  114. `non_aggregatable_indices`::
  115. The list of indices where this field is not aggregatable, or null if all
  116. indices have the same definition for the field.
  117. `non_dimension_indices`::
  118. experimental:[]
  119. If this list is present in response then some indices have the field marked as a dimension and other indices, the
  120. ones in this list, do not.
  121. `metric_conflicts_indices`::
  122. experimental:[]
  123. The list of indices where this field is present if these indices don't have the same `time_series_metric` value for
  124. this field.
  125. `meta`::
  126. Merged metadata across all indices as a map of string keys to arrays of values.
  127. A value length of 1 indicates that all indices had the same value for this key,
  128. while a length of 2 or more indicates that not all indices had the same value
  129. for this key.
  130. [[search-field-caps-api-example]]
  131. ==== {api-examples-title}
  132. The request can be restricted to specific data streams and indices:
  133. [source,console]
  134. --------------------------------------------------
  135. GET my-index-000001/_field_caps?fields=rating
  136. --------------------------------------------------
  137. // TEST[setup:my_index]
  138. The next example API call requests information about the `rating` and the
  139. `title` fields:
  140. [source,console]
  141. --------------------------------------------------
  142. GET _field_caps?fields=rating,title
  143. --------------------------------------------------
  144. The API returns the following response:
  145. [source,console-result]
  146. --------------------------------------------------
  147. {
  148. "indices": [ "index1", "index2", "index3", "index4", "index5" ],
  149. "fields": {
  150. "rating": { <1>
  151. "long": {
  152. "metadata_field": false,
  153. "searchable": true,
  154. "aggregatable": false,
  155. "indices": [ "index1", "index2" ],
  156. "non_aggregatable_indices": [ "index1" ] <2>
  157. },
  158. "keyword": {
  159. "metadata_field": false,
  160. "searchable": false,
  161. "aggregatable": true,
  162. "indices": [ "index3", "index4" ],
  163. "non_searchable_indices": [ "index4" ] <3>
  164. }
  165. },
  166. "title": { <4>
  167. "text": {
  168. "metadata_field": false,
  169. "searchable": true,
  170. "aggregatable": false
  171. }
  172. }
  173. }
  174. }
  175. --------------------------------------------------
  176. // TESTRESPONSE[skip:historically skipped]
  177. <1> The field `rating` is defined as a long in `index1` and `index2`
  178. and as a `keyword` in `index3` and `index4`.
  179. <2> The field `rating` is not aggregatable in `index1`.
  180. <3> The field `rating` is not searchable in `index4`.
  181. <4> The field `title` is defined as `text` in all indices.
  182. By default unmapped fields are ignored. You can include them in the response by
  183. adding a parameter called `include_unmapped` in the request:
  184. [source,console]
  185. --------------------------------------------------
  186. GET _field_caps?fields=rating,title&include_unmapped
  187. --------------------------------------------------
  188. In which case the response will contain an entry for each field that is present
  189. in some indices but not all:
  190. [source,console-result]
  191. --------------------------------------------------
  192. {
  193. "indices": [ "index1", "index2", "index3" ],
  194. "fields": {
  195. "rating": {
  196. "long": {
  197. "metadata_field": false,
  198. "searchable": true,
  199. "aggregatable": false,
  200. "indices": [ "index1", "index2" ],
  201. "non_aggregatable_indices": [ "index1" ]
  202. },
  203. "keyword": {
  204. "metadata_field": false,
  205. "searchable": false,
  206. "aggregatable": true,
  207. "indices": [ "index3", "index4" ],
  208. "non_searchable_indices": [ "index4" ]
  209. },
  210. "unmapped": { <1>
  211. "metadata_field": false,
  212. "indices": [ "index5" ],
  213. "searchable": false,
  214. "aggregatable": false
  215. }
  216. },
  217. "title": {
  218. "text": {
  219. "metadata_field": false,
  220. "indices": [ "index1", "index2", "index3", "index4" ],
  221. "searchable": true,
  222. "aggregatable": false
  223. },
  224. "unmapped": { <2>
  225. "metadata_field": false,
  226. "indices": [ "index5" ],
  227. "searchable": false,
  228. "aggregatable": false
  229. }
  230. }
  231. }
  232. }
  233. --------------------------------------------------
  234. // TESTRESPONSE[skip:historically skipped]
  235. <1> The `rating` field is unmapped` in `index5`.
  236. <2> The `title` field is unmapped` in `index5`.
  237. It is also possible to filter indices with a query:
  238. [source,console]
  239. --------------------------------------------------
  240. POST my-index-*/_field_caps?fields=rating
  241. {
  242. "index_filter": {
  243. "range": {
  244. "@timestamp": {
  245. "gte": "2018"
  246. }
  247. }
  248. }
  249. }
  250. --------------------------------------------------
  251. // TEST[setup:my_index]
  252. In which case indices that rewrite the provided filter to `match_none` on every shard
  253. will be filtered from the response.
  254. --
  255. [IMPORTANT]
  256. ====
  257. The filtering is done on a best-effort basis, it uses index statistics and mappings
  258. to rewrite queries to `match_none` instead of fully executing the request.
  259. For instance a `range` query over a `date` field can rewrite to `match_none`
  260. if all documents within a shard (including deleted documents) are outside
  261. of the provided range.
  262. However, not all queries can rewrite to `match_none` so this API may return
  263. an index even if the provided filter matches no document.
  264. ====
  265. --