1
0

api-conventions.asciidoc 8.1 KB

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