field-caps.asciidoc 7.4 KB

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