field-caps.asciidoc 7.2 KB

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