api-conventions.asciidoc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. [[api-conventions]]
  2. = API Conventions
  3. [partintro]
  4. --
  5. The *elasticsearch* REST APIs are exposed using <<modules-http,JSON over HTTP>>.
  6. The conventions listed in this chapter can be applied throughout the REST
  7. API, unless otherwise specified.
  8. * <<multi-index>>
  9. * <<common-options>>
  10. --
  11. [[multi-index]]
  12. == Multiple Indices
  13. Most APIs that refer to an `index` parameter support execution across multiple indices,
  14. using simple `test1,test2,test3` notation (or `_all` for all indices). It also
  15. support wildcards, for example: `test*`, and the ability to "add" (`+`)
  16. and "remove" (`-`), for example: `+test*,-test3`.
  17. All multi indices API support the following url query string parameters:
  18. `ignore_unavailable`::
  19. Controls whether to ignore if any specified indices are unavailable, this
  20. includes indices that don't exist or closed indices. Either `true` or `false`
  21. can be specified.
  22. `allow_no_indices`::
  23. Controls whether to fail if a wildcard indices expressions results into no
  24. concrete indices. Either `true` or `false` can be specified. For example if
  25. the wildcard expression `foo*` is specified and no indices are available that
  26. start with `foo` then depending on this setting the request will fail. This
  27. setting is also applicable when `_all`, `*` or no index has been specified. This
  28. settings also applies for aliases, in case an alias points to a closed index.
  29. `expand_wildcards`::
  30. Controls to what kind of concrete indices wildcard indices expression expand
  31. to. If `open` is specified then the wildcard expression is expanded to only
  32. open indices and if `closed` is specified then the wildcard expression is
  33. expanded only to closed indices. Also both values (`open,closed`) can be
  34. specified to expand to all indices.
  35. If `none` is specified then wildcard expansion will be disabled and if `all`
  36. is specified, wildcard expressions will expand to all indices (this is equivalent
  37. to specifying `open,closed`).
  38. The defaults settings for the above parameters depend on the api being used.
  39. NOTE: Single index APIs such as the <<docs>> and the
  40. <<indices-aliases,single-index `alias` APIs>> do not support multiple indices.
  41. [[common-options]]
  42. == Common options
  43. The following options can be applied to all of the REST APIs.
  44. [float]
  45. === Pretty Results
  46. When appending `?pretty=true` to any request made, the JSON returned
  47. will be pretty formatted (use it for debugging only!). Another option is
  48. to set `?format=yaml` which will cause the result to be returned in the
  49. (sometimes) more readable yaml format.
  50. [float]
  51. === Human readable output
  52. Statistics are returned in a format suitable for humans
  53. (eg `"exists_time": "1h"` or `"size": "1kb"`) and for computers
  54. (eg `"exists_time_in_millis": 3600000` or `"size_in_bytes": 1024`).
  55. The human readable values can be turned off by adding `?human=false`
  56. to the query string. This makes sense when the stats results are
  57. being consumed by a monitoring tool, rather than intended for human
  58. consumption. The default for the `human` flag is
  59. `false`.
  60. [float]
  61. === Flat Settings
  62. The `flat_settings` flag affects rendering of the lists of settings. When
  63. `flat_settings` flag is `true` settings are returned in a flat format:
  64. [source,js]
  65. --------------------------------------------------
  66. {
  67. "persistent" : { },
  68. "transient" : {
  69. "discovery.zen.minimum_master_nodes" : "1"
  70. }
  71. }
  72. --------------------------------------------------
  73. When the `flat_settings` flag is `false` settings are returned in a more
  74. human readable structured format:
  75. [source,js]
  76. --------------------------------------------------
  77. {
  78. "persistent" : { },
  79. "transient" : {
  80. "discovery" : {
  81. "zen" : {
  82. "minimum_master_nodes" : "1"
  83. }
  84. }
  85. }
  86. }
  87. --------------------------------------------------
  88. By default the `flat_settings` is set to `false`.
  89. [float]
  90. === Parameters
  91. Rest parameters (when using HTTP, map to HTTP URL parameters) follow the
  92. convention of using underscore casing.
  93. [float]
  94. === Boolean Values
  95. All REST APIs parameters (both request parameters and JSON body) support
  96. providing boolean "false" as the values: `false`, `0`, `no` and `off`.
  97. All other values are considered "true". Note, this is not related to
  98. fields within a document indexed treated as boolean fields.
  99. [float]
  100. === Number Values
  101. All REST APIs support providing numbered parameters as `string` on top
  102. of supporting the native JSON number types.
  103. [[time-units]]
  104. [float]
  105. === Time units
  106. Whenever durations need to be specified, eg for a `timeout` parameter, the duration
  107. can be specified as a whole number representing time in milliseconds, or as a time value like `2d` for 2 days. The supported units are:
  108. [horizontal]
  109. `y`:: Year
  110. `M`:: Month
  111. `w`:: Week
  112. `d`:: Day
  113. `h`:: Hour
  114. `m`:: Minute
  115. `s`:: Second
  116. [[distance-units]]
  117. [float]
  118. === Distance Units
  119. Wherever distances need to be specified, such as the `distance` parameter in
  120. the <<query-dsl-geo-distance-query>>), the default unit if none is specified is
  121. the meter. Distances can be specified in other units, such as `"1km"` or
  122. `"2mi"` (2 miles).
  123. The full list of units is listed below:
  124. [horizontal]
  125. Mile:: `mi` or `miles`
  126. Yard:: `yd` or `yards`
  127. Feet:: `ft` or `feet`
  128. Inch:: `in` or `inch`
  129. Kilometer:: `km` or `kilometers`
  130. Meter:: `m` or `meters`
  131. Centimeter:: `cm` or `centimeters`
  132. Millimeter:: `mm` or `millimeters`
  133. Nautical mile:: `NM`, `nmi` or `nauticalmiles`
  134. The `precision` parameter in the <<query-dsl-geohash-cell-query>> accepts
  135. distances with the above units, but if no unit is specified, then the
  136. precision is interpreted as the length of the geohash.
  137. [[fuzziness]]
  138. [float]
  139. === Fuzziness
  140. Some queries and APIs support parameters to allow inexact _fuzzy_ matching,
  141. using the `fuzziness` parameter. The `fuzziness` parameter is context
  142. sensitive which means that it depends on the type of the field being queried:
  143. [float]
  144. ==== Numeric, date and IPv4 fields
  145. When querying numeric, date and IPv4 fields, `fuzziness` is interpreted as a
  146. `+/-` margin. It behaves like a <<query-dsl-range-query>> where:
  147. -fuzziness <= field value <= +fuzziness
  148. The `fuzziness` parameter should be set to a numeric value, eg `2` or `2.0`. A
  149. `date` field interprets a long as milliseconds, but also accepts a string
  150. containing a time value -- `"1h"` -- as explained in <<time-units>>. An `ip`
  151. field accepts a long or another IPv4 address (which will be converted into a
  152. long).
  153. [float]
  154. ==== String fields
  155. When querying `string` fields, `fuzziness` is interpreted as a
  156. http://en.wikipedia.org/wiki/Levenshtein_distance[Levenshtein Edit Distance]
  157. -- the number of one character changes that need to be made to one string to
  158. make it the same as another string.
  159. The `fuzziness` parameter can be specified as:
  160. `0`, `1`, `2`::
  161. the maximum allowed Levenshtein Edit Distance (or number of edits)
  162. `AUTO`::
  163. +
  164. --
  165. generates an edit distance based on the length of the term. For lengths:
  166. `0..1`:: must match exactly
  167. `1..5`:: one edit allowed
  168. `>5`:: two edits allowed
  169. `AUTO` should generally be the preferred value for `fuzziness`.
  170. --
  171. `0.0..1.0`::
  172. converted into an edit distance using the formula: `length(term) * (1.0 -
  173. fuzziness)`, eg a `fuzziness` of `0.6` with a term of length 10 would result
  174. in an edit distance of `4`. Note: in all APIs the maximum allowed edit distance is `2`.
  175. [float]
  176. === Result Casing
  177. All REST APIs accept the `case` parameter. When set to `camelCase`, all
  178. field names in the result will be returned in camel casing, otherwise,
  179. underscore casing will be used. Note, this does not apply to the source
  180. document indexed.
  181. [float]
  182. === Request body in query string
  183. For libraries that don't accept a request body for non-POST requests,
  184. you can pass the request body as the `source` query string parameter
  185. instead.
  186. [[url-access-control]]
  187. == URL-based access control
  188. Many users use a proxy with URL-based access control to secure access to
  189. Elasticsearch indices. For <<search-multi-search,multi-search>>,
  190. <<docs-multi-get,multi-get>> and <<docs-bulk,bulk>> requests, the user has
  191. the choice of specifying an index in the URL and on each individual request
  192. within the request body. This can make URL-based access control challenging.
  193. To prevent the user from overriding the index which has been specified in the
  194. URL, add this setting to the `config.yml` file:
  195. rest.action.multi.allow_explicit_index: false
  196. The default value is `true`, but when set to `false`, Elasticsearch will
  197. reject requests that have an explicit index specified in the request body.