field-caps.asciidoc 6.8 KB

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