api-conventions.asciidoc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. [[api-conventions]]
  2. == API conventions
  3. The {es} REST APIs are exposed using JSON over HTTP. The JSON request body must
  4. be UTF-8 encoded. {es} ignores any other encoding headings sent with a request.
  5. Responses are also UTF-8 encoded.
  6. The conventions listed in this chapter can be applied throughout the REST
  7. API, unless otherwise specified.
  8. * <<multi-index>>
  9. * <<date-math-index-names>>
  10. * <<cron-expressions>>
  11. * <<common-options>>
  12. * <<url-access-control>>
  13. [[multi-index]]
  14. === Multi-target syntax
  15. Most APIs that accept a `<data-stream>`, `<index>`, or `<target>` request path
  16. parameter also support _multi-target syntax_.
  17. In multi-target syntax, you can use a comma-separated list to run a request on
  18. multiple resources, such as data streams, indices, or index aliases:
  19. `test1,test2,test3`. You can also use {wikipedia}/Glob_(programming)[glob-like]
  20. wildcard (`*`) expressions to target resources that match a pattern: `test*` or
  21. `*test` or `te*t` or `*test*`.
  22. You can exclude targets using the `-` character: `test*,-test3`.
  23. IMPORTANT: Index aliases are resolved after wildcard expressions. This can
  24. result in a request that targets an excluded alias. For example, if `test3` is
  25. an index alias, the pattern `test*,-test3` still targets the indices for
  26. `test3`. To avoid this, exclude the concrete indices for the alias instead.
  27. Multi-target APIs that can target indices support the following query
  28. string parameters:
  29. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  30. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  31. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  32. The defaults settings for the above parameters depend on the API being used.
  33. Some multi-target APIs that can target indices also support the following query
  34. string parameter:
  35. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=ignore_throttled]
  36. NOTE: Single index APIs, such as the <<docs>> and
  37. <<indices-aliases,single-index `alias` APIs>>, do not support multi-target
  38. syntax.
  39. [[hidden-indices]]
  40. ==== Hidden data streams and indices
  41. For most APIs, wildcard expressions do not match hidden data streams and indices
  42. by default. To match hidden data streams and indices using a wildcard
  43. expression, you must specify the `expand_wildcards` query parameter.
  44. You can create hidden data streams by setting
  45. <<data-stream-hidden,`data_stream.hidden`>> to `true` in the stream's matching
  46. index template. You can hide indices using the <<index-hidden,`index.hidden`>>
  47. index setting.
  48. The backing indices for data streams are hidden automatically. Some features,
  49. such as {ml}, store information in hidden indices.
  50. Global index templates that match all indices are not applied to hidden indices.
  51. [[system-indices]]
  52. ==== System indices
  53. {es} modules and plugins can store configuration and state information in internal _system indices_.
  54. You should not directly access or modify system indices
  55. as they contain data essential to the operation of the system.
  56. IMPORTANT: Direct access to system indices is deprecated and
  57. will no longer be allowed in the next major version.
  58. [[date-math-index-names]]
  59. === Date math support in index and index alias names
  60. Date math name resolution lets you to search a range of time series indices or
  61. index aliases rather than searching all of your indices and filtering the
  62. results. Limiting the number of searched indices reduces cluster load and
  63. improves search performance. For example, if you are searching for errors in
  64. your daily logs, you can use a date math name template to restrict the search to
  65. the past two days.
  66. Most APIs that accept an index or index alias argument support date math. A date
  67. math name takes the following form:
  68. [source,txt]
  69. ----------------------------------------------------------------------
  70. <static_name{date_math_expr{date_format|time_zone}}>
  71. ----------------------------------------------------------------------
  72. Where:
  73. [horizontal]
  74. `static_name`:: Static text
  75. `date_math_expr`:: Dynamic date math expression that computes the date dynamically
  76. `date_format`:: Optional format in which the computed date should be rendered. Defaults to `yyyy.MM.dd`. Format should be compatible with java-time https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
  77. `time_zone`:: Optional time zone. Defaults to `UTC`.
  78. NOTE: Pay attention to the usage of small vs capital letters used in the `date_format`. For example:
  79. `mm` denotes minute of hour, while `MM` denotes month of year. Similarly `hh` denotes the hour in the
  80. `1-12` range in combination with `AM/PM`, while `HH` denotes the hour in the `0-23` 24-hour range.
  81. Date math expressions are resolved locale-independent. Consequently, it is not possible to use any other
  82. calendars than the Gregorian calendar.
  83. You must enclose date math names in angle brackets. If you use the name in a
  84. request path, special characters must be URI encoded. For example:
  85. [source,console]
  86. ----
  87. # PUT /<my-index-{now/d}>
  88. PUT /%3Cmy-index-%7Bnow%2Fd%7D%3E
  89. ----
  90. [NOTE]
  91. .Percent encoding of date math characters
  92. ======================================================
  93. The special characters used for date rounding must be URI encoded as follows:
  94. [horizontal]
  95. `<`:: `%3C`
  96. `>`:: `%3E`
  97. `/`:: `%2F`
  98. `{`:: `%7B`
  99. `}`:: `%7D`
  100. `|`:: `%7C`
  101. `+`:: `%2B`
  102. `:`:: `%3A`
  103. `,`:: `%2C`
  104. ======================================================
  105. The following example shows different forms of date math names and the final names
  106. they resolve to given the current time is 22nd March 2024 noon UTC.
  107. [options="header"]
  108. |======
  109. | Expression |Resolves to
  110. | `<logstash-{now/d}>` | `logstash-2024.03.22`
  111. | `<logstash-{now/M}>` | `logstash-2024.03.01`
  112. | `<logstash-{now/M{yyyy.MM}}>` | `logstash-2024.03`
  113. | `<logstash-{now/M-1M{yyyy.MM}}>` | `logstash-2024.02`
  114. | `<logstash-{now/d{yyyy.MM.dd\|+12:00}}>` | `logstash-2024.03.23`
  115. |======
  116. To use the characters `{` and `}` in the static part of a name template, escape them
  117. with a backslash `\`, for example:
  118. * `<elastic\\{ON\\}-{now/M}>` resolves to `elastic{ON}-2024.03.01`
  119. The following example shows a search request that searches the Logstash indices for the past
  120. three days, assuming the indices use the default Logstash index name format,
  121. `logstash-YYYY.MM.dd`.
  122. [source,console]
  123. ----------------------------------------------------------------------
  124. # GET /<logstash-{now/d-2d}>,<logstash-{now/d-1d}>,<logstash-{now/d}>/_search
  125. GET /%3Clogstash-%7Bnow%2Fd-2d%7D%3E%2C%3Clogstash-%7Bnow%2Fd-1d%7D%3E%2C%3Clogstash-%7Bnow%2Fd%7D%3E/_search
  126. {
  127. "query" : {
  128. "match": {
  129. "test": "data"
  130. }
  131. }
  132. }
  133. ----------------------------------------------------------------------
  134. // TEST[s/^/PUT logstash-2016.09.20\nPUT logstash-2016.09.19\nPUT logstash-2016.09.18\n/]
  135. // TEST[s/now/2016.09.20%7C%7C/]
  136. include::rest-api/cron-expressions.asciidoc[]
  137. [[common-options]]
  138. === Common options
  139. The following options can be applied to all of the REST APIs.
  140. [discrete]
  141. ==== Pretty Results
  142. When appending `?pretty=true` to any request made, the JSON returned
  143. will be pretty formatted (use it for debugging only!). Another option is
  144. to set `?format=yaml` which will cause the result to be returned in the
  145. (sometimes) more readable yaml format.
  146. [discrete]
  147. ==== Human readable output
  148. Statistics are returned in a format suitable for humans
  149. (e.g. `"exists_time": "1h"` or `"size": "1kb"`) and for computers
  150. (e.g. `"exists_time_in_millis": 3600000` or `"size_in_bytes": 1024`).
  151. The human readable values can be turned off by adding `?human=false`
  152. to the query string. This makes sense when the stats results are
  153. being consumed by a monitoring tool, rather than intended for human
  154. consumption. The default for the `human` flag is
  155. `false`.
  156. [[date-math]]
  157. [discrete]
  158. ==== Date Math
  159. Most parameters which accept a formatted date value -- such as `gt` and `lt`
  160. in <<query-dsl-range-query,`range` queries>>, or `from` and `to`
  161. in <<search-aggregations-bucket-daterange-aggregation,`daterange`
  162. aggregations>> -- understand date maths.
  163. The expression starts with an anchor date, which can either be `now`, or a
  164. date string ending with `||`. This anchor date can optionally be followed by
  165. one or more maths expressions:
  166. * `+1h`: Add one hour
  167. * `-1d`: Subtract one day
  168. * `/d`: Round down to the nearest day
  169. The supported time units differ from those supported by <<time-units, time units>> for durations.
  170. The supported units are:
  171. [horizontal]
  172. `y`:: Years
  173. `M`:: Months
  174. `w`:: Weeks
  175. `d`:: Days
  176. `h`:: Hours
  177. `H`:: Hours
  178. `m`:: Minutes
  179. `s`:: Seconds
  180. Assuming `now` is `2001-01-01 12:00:00`, some examples are:
  181. [horizontal]
  182. `now+1h`:: `now` in milliseconds plus one hour. Resolves to: `2001-01-01 13:00:00`
  183. `now-1h`:: `now` in milliseconds minus one hour. Resolves to: `2001-01-01 11:00:00`
  184. `now-1h/d`:: `now` in milliseconds minus one hour, rounded down to UTC 00:00. Resolves to: `2001-01-01 00:00:00`
  185. `2001.02.01\|\|+1M/d`:: `2001-02-01` in milliseconds plus one month. Resolves to: `2001-03-01 00:00:00`
  186. [discrete]
  187. [[common-options-response-filtering]]
  188. ==== Response Filtering
  189. All REST APIs accept a `filter_path` parameter that can be used to reduce
  190. the response returned by Elasticsearch. This parameter takes a comma
  191. separated list of filters expressed with the dot notation:
  192. [source,console]
  193. --------------------------------------------------
  194. GET /_search?q=kimchy&filter_path=took,hits.hits._id,hits.hits._score
  195. --------------------------------------------------
  196. // TEST[setup:my_index]
  197. Responds:
  198. [source,console-result]
  199. --------------------------------------------------
  200. {
  201. "took" : 3,
  202. "hits" : {
  203. "hits" : [
  204. {
  205. "_id" : "0",
  206. "_score" : 1.6375021
  207. }
  208. ]
  209. }
  210. }
  211. --------------------------------------------------
  212. // TESTRESPONSE[s/"took" : 3/"took" : $body.took/]
  213. // TESTRESPONSE[s/1.6375021/$body.hits.hits.0._score/]
  214. It also supports the `*` wildcard character to match any field or part
  215. of a field's name:
  216. [source,console]
  217. --------------------------------------------------
  218. GET /_cluster/state?filter_path=metadata.indices.*.stat*
  219. --------------------------------------------------
  220. // TEST[s/^/PUT my-index-000001\n/]
  221. Responds:
  222. [source,console-result]
  223. --------------------------------------------------
  224. {
  225. "metadata" : {
  226. "indices" : {
  227. "my-index-000001": {"state": "open"}
  228. }
  229. }
  230. }
  231. --------------------------------------------------
  232. And the `**` wildcard can be used to include fields without knowing the
  233. exact path of the field. For example, we can return the Lucene version
  234. of every segment with this request:
  235. [source,console]
  236. --------------------------------------------------
  237. GET /_cluster/state?filter_path=routing_table.indices.**.state
  238. --------------------------------------------------
  239. // TEST[s/^/PUT my-index-000001\n/]
  240. Responds:
  241. [source,console-result]
  242. --------------------------------------------------
  243. {
  244. "routing_table": {
  245. "indices": {
  246. "my-index-000001": {
  247. "shards": {
  248. "0": [{"state": "STARTED"}, {"state": "UNASSIGNED"}]
  249. }
  250. }
  251. }
  252. }
  253. }
  254. --------------------------------------------------
  255. It is also possible to exclude one or more fields by prefixing the filter with the char `-`:
  256. [source,console]
  257. --------------------------------------------------
  258. GET /_count?filter_path=-_shards
  259. --------------------------------------------------
  260. // TEST[setup:my_index]
  261. Responds:
  262. [source,console-result]
  263. --------------------------------------------------
  264. {
  265. "count" : 5
  266. }
  267. --------------------------------------------------
  268. And for more control, both inclusive and exclusive filters can be combined in the same expression. In
  269. this case, the exclusive filters will be applied first and the result will be filtered again using the
  270. inclusive filters:
  271. [source,console]
  272. --------------------------------------------------
  273. GET /_cluster/state?filter_path=metadata.indices.*.state,-metadata.indices.logstash-*
  274. --------------------------------------------------
  275. // TEST[s/^/PUT my-index-000001\nPUT my-index-000002\nPUT my-index-000003\nPUT logstash-2016.01\n/]
  276. Responds:
  277. [source,console-result]
  278. --------------------------------------------------
  279. {
  280. "metadata" : {
  281. "indices" : {
  282. "my-index-000001" : {"state" : "open"},
  283. "my-index-000002" : {"state" : "open"},
  284. "my-index-000003" : {"state" : "open"}
  285. }
  286. }
  287. }
  288. --------------------------------------------------
  289. Note that Elasticsearch sometimes returns directly the raw value of a field,
  290. like the `_source` field. If you want to filter `_source` fields, you should
  291. consider combining the already existing `_source` parameter (see
  292. <<get-source-filtering,Get API>> for more details) with the `filter_path`
  293. parameter like this:
  294. [source,console]
  295. --------------------------------------------------
  296. POST /library/_doc?refresh
  297. {"title": "Book #1", "rating": 200.1}
  298. POST /library/_doc?refresh
  299. {"title": "Book #2", "rating": 1.7}
  300. POST /library/_doc?refresh
  301. {"title": "Book #3", "rating": 0.1}
  302. GET /_search?filter_path=hits.hits._source&_source=title&sort=rating:desc
  303. --------------------------------------------------
  304. [source,console-result]
  305. --------------------------------------------------
  306. {
  307. "hits" : {
  308. "hits" : [ {
  309. "_source":{"title":"Book #1"}
  310. }, {
  311. "_source":{"title":"Book #2"}
  312. }, {
  313. "_source":{"title":"Book #3"}
  314. } ]
  315. }
  316. }
  317. --------------------------------------------------
  318. [discrete]
  319. ==== Flat Settings
  320. The `flat_settings` flag affects rendering of the lists of settings. When the
  321. `flat_settings` flag is `true`, settings are returned in a flat format:
  322. [source,console]
  323. --------------------------------------------------
  324. GET my-index-000001/_settings?flat_settings=true
  325. --------------------------------------------------
  326. // TEST[setup:my_index]
  327. Returns:
  328. [source,console-result]
  329. --------------------------------------------------
  330. {
  331. "my-index-000001" : {
  332. "settings": {
  333. "index.number_of_replicas": "1",
  334. "index.number_of_shards": "1",
  335. "index.creation_date": "1474389951325",
  336. "index.uuid": "n6gzFZTgS664GUfx0Xrpjw",
  337. "index.version.created": ...,
  338. "index.routing.allocation.include._tier_preference" : "data_content",
  339. "index.provided_name" : "my-index-000001"
  340. }
  341. }
  342. }
  343. --------------------------------------------------
  344. // TESTRESPONSE[s/1474389951325/$body.my-index-000001.settings.index\\\\.creation_date/]
  345. // TESTRESPONSE[s/n6gzFZTgS664GUfx0Xrpjw/$body.my-index-000001.settings.index\\\\.uuid/]
  346. // TESTRESPONSE[s/"index.version.created": \.\.\./"index.version.created": $body.my-index-000001.settings.index\\\\.version\\\\.created/]
  347. When the `flat_settings` flag is `false`, settings are returned in a more
  348. human readable structured format:
  349. [source,console]
  350. --------------------------------------------------
  351. GET my-index-000001/_settings?flat_settings=false
  352. --------------------------------------------------
  353. // TEST[setup:my_index]
  354. Returns:
  355. [source,console-result]
  356. --------------------------------------------------
  357. {
  358. "my-index-000001" : {
  359. "settings" : {
  360. "index" : {
  361. "number_of_replicas": "1",
  362. "number_of_shards": "1",
  363. "creation_date": "1474389951325",
  364. "uuid": "n6gzFZTgS664GUfx0Xrpjw",
  365. "version": {
  366. "created": ...
  367. },
  368. "routing": {
  369. "allocation": {
  370. "include": {
  371. "_tier_preference": "data_content"
  372. }
  373. }
  374. },
  375. "provided_name" : "my-index-000001"
  376. }
  377. }
  378. }
  379. }
  380. --------------------------------------------------
  381. // TESTRESPONSE[s/1474389951325/$body.my-index-000001.settings.index.creation_date/]
  382. // TESTRESPONSE[s/n6gzFZTgS664GUfx0Xrpjw/$body.my-index-000001.settings.index.uuid/]
  383. // TESTRESPONSE[s/"created": \.\.\./"created": $body.my-index-000001.settings.index.version.created/]
  384. By default `flat_settings` is set to `false`.
  385. [discrete]
  386. [[api-conventions-parameters]]
  387. ==== Parameters
  388. Rest parameters (when using HTTP, map to HTTP URL parameters) follow the
  389. convention of using underscore casing.
  390. [discrete]
  391. ==== Boolean Values
  392. All REST API parameters (both request parameters and JSON body) support
  393. providing boolean "false" as the value `false` and boolean "true" as the
  394. value `true`. All other values will raise an error.
  395. [discrete]
  396. ==== Number Values
  397. All REST APIs support providing numbered parameters as `string` on top
  398. of supporting the native JSON number types.
  399. [[time-units]]
  400. [discrete]
  401. ==== Time units
  402. Whenever durations need to be specified, e.g. for a `timeout` parameter, the duration must specify
  403. the unit, like `2d` for 2 days. The supported units are:
  404. [horizontal]
  405. `d`:: Days
  406. `h`:: Hours
  407. `m`:: Minutes
  408. `s`:: Seconds
  409. `ms`:: Milliseconds
  410. `micros`:: Microseconds
  411. `nanos`:: Nanoseconds
  412. [[byte-units]]
  413. [discrete]
  414. ==== Byte size units
  415. Whenever the byte size of data needs to be specified, e.g. when setting a buffer size
  416. parameter, the value must specify the unit, like `10kb` for 10 kilobytes. Note that
  417. these units use powers of 1024, so `1kb` means 1024 bytes. The supported units are:
  418. [horizontal]
  419. `b`:: Bytes
  420. `kb`:: Kilobytes
  421. `mb`:: Megabytes
  422. `gb`:: Gigabytes
  423. `tb`:: Terabytes
  424. `pb`:: Petabytes
  425. [[size-units]]
  426. [discrete]
  427. ==== Unit-less quantities
  428. Unit-less quantities means that they don't have a "unit" like "bytes" or "Hertz" or "meter" or "long tonne".
  429. If one of these quantities is large we'll print it out like 10m for 10,000,000 or 7k for 7,000. We'll still print 87
  430. when we mean 87 though. These are the supported multipliers:
  431. [horizontal]
  432. `k`:: Kilo
  433. `m`:: Mega
  434. `g`:: Giga
  435. `t`:: Tera
  436. `p`:: Peta
  437. [[distance-units]]
  438. [discrete]
  439. ==== Distance Units
  440. Wherever distances need to be specified, such as the `distance` parameter in
  441. the <<query-dsl-geo-distance-query>>), the default unit is meters if none is specified.
  442. Distances can be specified in other units, such as `"1km"` or
  443. `"2mi"` (2 miles).
  444. The full list of units is listed below:
  445. [horizontal]
  446. Mile:: `mi` or `miles`
  447. Yard:: `yd` or `yards`
  448. Feet:: `ft` or `feet`
  449. Inch:: `in` or `inch`
  450. Kilometer:: `km` or `kilometers`
  451. Meter:: `m` or `meters`
  452. Centimeter:: `cm` or `centimeters`
  453. Millimeter:: `mm` or `millimeters`
  454. Nautical mile:: `NM`, `nmi`, or `nauticalmiles`
  455. [[fuzziness]]
  456. [discrete]
  457. ==== Fuzziness
  458. Some queries and APIs support parameters to allow inexact _fuzzy_ matching,
  459. using the `fuzziness` parameter.
  460. When querying `text` or `keyword` fields, `fuzziness` is interpreted as a
  461. {wikipedia}/Levenshtein_distance[Levenshtein Edit Distance]
  462. -- the number of one character changes that need to be made to one string to
  463. make it the same as another string.
  464. The `fuzziness` parameter can be specified as:
  465. [horizontal]
  466. `0`, `1`, `2`::
  467. The maximum allowed Levenshtein Edit Distance (or number of edits)
  468. `AUTO`::
  469. +
  470. --
  471. Generates an edit distance based on the length of the term.
  472. Low and high distance arguments may be optionally provided `AUTO:[low],[high]`. If not specified,
  473. the default values are 3 and 6, equivalent to `AUTO:3,6` that make for lengths:
  474. `0..2`:: Must match exactly
  475. `3..5`:: One edit allowed
  476. `>5`:: Two edits allowed
  477. `AUTO` should generally be the preferred value for `fuzziness`.
  478. --
  479. [discrete]
  480. [[common-options-error-options]]
  481. ==== Enabling stack traces
  482. By default when a request returns an error Elasticsearch doesn't include the
  483. stack trace of the error. You can enable that behavior by setting the
  484. `error_trace` url parameter to `true`. For example, by default when you send an
  485. invalid `size` parameter to the `_search` API:
  486. [source,console]
  487. ----------------------------------------------------------------------
  488. POST /my-index-000001/_search?size=surprise_me
  489. ----------------------------------------------------------------------
  490. // TEST[s/surprise_me/surprise_me&error_trace=false/ catch:bad_request]
  491. // Since the test system sends error_trace=true by default we have to override
  492. The response looks like:
  493. [source,console-result]
  494. ----------------------------------------------------------------------
  495. {
  496. "error" : {
  497. "root_cause" : [
  498. {
  499. "type" : "illegal_argument_exception",
  500. "reason" : "Failed to parse int parameter [size] with value [surprise_me]"
  501. }
  502. ],
  503. "type" : "illegal_argument_exception",
  504. "reason" : "Failed to parse int parameter [size] with value [surprise_me]",
  505. "caused_by" : {
  506. "type" : "number_format_exception",
  507. "reason" : "For input string: \"surprise_me\""
  508. }
  509. },
  510. "status" : 400
  511. }
  512. ----------------------------------------------------------------------
  513. But if you set `error_trace=true`:
  514. [source,console]
  515. ----------------------------------------------------------------------
  516. POST /my-index-000001/_search?size=surprise_me&error_trace=true
  517. ----------------------------------------------------------------------
  518. // TEST[catch:bad_request]
  519. The response looks like:
  520. [source,console-result]
  521. ----------------------------------------------------------------------
  522. {
  523. "error": {
  524. "root_cause": [
  525. {
  526. "type": "illegal_argument_exception",
  527. "reason": "Failed to parse int parameter [size] with value [surprise_me]",
  528. "stack_trace": "Failed to parse int parameter [size] with value [surprise_me]]; nested: IllegalArgumentException..."
  529. }
  530. ],
  531. "type": "illegal_argument_exception",
  532. "reason": "Failed to parse int parameter [size] with value [surprise_me]",
  533. "stack_trace": "java.lang.IllegalArgumentException: Failed to parse int parameter [size] with value [surprise_me]\n at org.elasticsearch.rest.RestRequest.paramAsInt(RestRequest.java:175)...",
  534. "caused_by": {
  535. "type": "number_format_exception",
  536. "reason": "For input string: \"surprise_me\"",
  537. "stack_trace": "java.lang.NumberFormatException: For input string: \"surprise_me\"\n at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)..."
  538. }
  539. },
  540. "status": 400
  541. }
  542. ----------------------------------------------------------------------
  543. // TESTRESPONSE[s/"stack_trace": "Failed to parse int parameter.+\.\.\."/"stack_trace": $body.error.root_cause.0.stack_trace/]
  544. // TESTRESPONSE[s/"stack_trace": "java.lang.IllegalArgum.+\.\.\."/"stack_trace": $body.error.stack_trace/]
  545. // TESTRESPONSE[s/"stack_trace": "java.lang.Number.+\.\.\."/"stack_trace": $body.error.caused_by.stack_trace/]
  546. [discrete]
  547. ==== Request body in query string
  548. For libraries that don't accept a request body for non-POST requests,
  549. you can pass the request body as the `source` query string parameter
  550. instead. When using this method, the `source_content_type` parameter
  551. should also be passed with a media type value that indicates the format
  552. of the source, such as `application/json`.
  553. [discrete]
  554. ==== Content-Type Requirements
  555. The type of the content sent in a request body must be specified using
  556. the `Content-Type` header. The value of this header must map to one of
  557. the supported formats that the API supports. Most APIs support JSON,
  558. YAML, CBOR, and SMILE. The bulk and multi-search APIs support NDJSON,
  559. JSON, and SMILE; other types will result in an error response.
  560. Additionally, when using the `source` query string parameter, the
  561. content type must be specified using the `source_content_type` query
  562. string parameter.
  563. [[url-access-control]]
  564. === URL-based access control
  565. Many users use a proxy with URL-based access control to secure access to
  566. {es} data streams and indices. For <<search-multi-search,multi-search>>,
  567. <<docs-multi-get,multi-get>>, and <<docs-bulk,bulk>> requests, the user has
  568. the choice of specifying a data stream or index in the URL and on each individual request
  569. within the request body. This can make URL-based access control challenging.
  570. To prevent the user from overriding the data stream or index specified in the
  571. URL, set `rest.action.multi.allow_explicit_index` to `false` in `elasticsearch.yml`.
  572. This causes {es} to
  573. reject requests that explicitly specify a data stream or index in the request body.