api-conventions.asciidoc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 `ignore_indices` option. Setting it to
  21. `missing` will cause indices that do not exists to be ignored from the
  22. execution. By default, when it's not set, the request will fail.
  23. NOTE: Single index APIs such as the <<docs>> and the
  24. <<indices-aliases,single-index `alias` APIs>> do not support multiple indices.
  25. [[common-options]]
  26. == Common options
  27. The following options can be applied to all of the REST APIs.
  28. [float]
  29. === Pretty Results
  30. When appending `?pretty=true` to any request made, the JSON returned
  31. will be pretty formatted (use it for debugging only!). Another option is
  32. to set `format=yaml` which will cause the result to be returned in the
  33. (sometimes) more readable yaml format.
  34. [float]
  35. === Human readable output
  36. Statistics are returned in a format suitable for humans
  37. (eg `"exists_time": "1h"` or `"size": "1kb"`) and for computers
  38. (eg `"exists_time_in_millis": 3600000`` or `"size_in_bytes": 1024`).
  39. The human readable values can be turned off by adding `?human=false`
  40. to the query string. This makes sense when the stats results are
  41. being consumed by a monitoring tool, rather than intended for human
  42. consumption. The default for the `human` flag is
  43. `false`. added[1.00.Beta,Previously defaulted to `true`]
  44. [float]
  45. === Parameters
  46. Rest parameters (when using HTTP, map to HTTP URL parameters) follow the
  47. convention of using underscore casing.
  48. [float]
  49. === Boolean Values
  50. All REST APIs parameters (both request parameters and JSON body) support
  51. providing boolean "false" as the values: `false`, `0`, `no` and `off`.
  52. All other values are considered "true". Note, this is not related to
  53. fields within a document indexed treated as boolean fields.
  54. [float]
  55. === Number Values
  56. All REST APIs support providing numbered parameters as `string` on top
  57. of supporting the native JSON number types.
  58. [[distance-units]]
  59. [float]
  60. === Distance Units
  61. Wherever distances need to be specified, such as the `distance` parameter in
  62. the <<query-dsl-geo-distance-filter>>) or the `precision` parameter in the
  63. <<query-dsl-geohash-cell-filter>>, the default unit if none is specified is
  64. the meter. Distances can be specified in other units, such as `"1km"` or
  65. `"2mi"` (2 miles).
  66. The full list of units is listed below:
  67. [horizontal]
  68. Mile:: `mi` or `miles`
  69. Yard:: `yd` or `yards`
  70. Inch:: `in` or `inch`
  71. Kilometer:: `km` or `kilometers`
  72. Meter:: `m` or `meters`
  73. Centimeter:: `cm` or `centimeters`
  74. Millimeter:: `mm` or `millimeters`
  75. [float]
  76. === Result Casing
  77. All REST APIs accept the `case` parameter. When set to `camelCase`, all
  78. field names in the result will be returned in camel casing, otherwise,
  79. underscore casing will be used. Note, this does not apply to the source
  80. document indexed.
  81. [float]
  82. === JSONP
  83. All REST APIs accept a `callback` parameter resulting in a
  84. http://en.wikipedia.org/wiki/JSONP[JSONP] result.
  85. [float]
  86. === Request body in query string
  87. For libraries that don't accept a request body for non-POST requests,
  88. you can pass the request body as the `source` query string parameter
  89. instead.
  90. [[url-access-control]]
  91. == URL-based access control
  92. Many users use a proxy with URL-based access control to secure access to
  93. Elasticsearch indices. For <<search-multi-search,multi-search>>,
  94. <<docs-multi-get,multi-get>> and <<docs-bulk,bulk>> requests, the user has
  95. the choice of specifying an index in the URL and on each individual request
  96. within the request body. This can make URL-based access control challenging.
  97. To prevent the user from overriding the index which has been specified in the
  98. URL, add this setting to the `config.yml` file:
  99. rest.action.multi.allow_explicit_index: false
  100. The default value is `true`, but when set to `false`, Elasticsearch will
  101. reject requests that have an explicit index specified in the request body.