api-conventions.asciidoc 9.0 KB

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