api-conventions.asciidoc 8.2 KB

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