| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 | [[api-conventions]]= API Conventions[partintro]--The *elasticsearch* REST APIs are exposed using:* <<modules-http,JSON over HTTP>>,* <<modules-thrift,thrift>>,* <<modules-memcached,memcached>>.The conventions listed in this chapter can be applied throughout the RESTAPI, unless otherwise specified.* <<multi-index>>* <<common-options>>--[[multi-index]]== Multiple IndicesMost APIs that refer to an `index` parameter support execution across multiple indices,using simple `test1,test2,test3` notation (or `_all` for all indices). It alsosupport wildcards, for example: `test*`, and the ability to "add" (`+`)and "remove" (`-`), for example: `+test*,-test3`.All multi indices API support the following url query string parameters:`ignore_unavailable`::Controls whether to ignore if any specified indices are unavailable, thisincludes indices that don't exist or closed indices. Either `true` or `false`can be specified.`allow_no_indices`::Controls whether to fail if a wildcard indices expressions results into noconcrete indices. Either `true` or `false` can be specified. For example ifthe wildcard expression `foo*` is specified and no indices are available thatstart with `foo` then depending on this setting the request will fail. Thissetting is also applicable when `_all`, `*` or no index has been specified.`expand_wildcards`::Controls to what kind of concrete indices wildcard indices expression expandto. If `open` is specified then the wildcard expression is expanded to onlyopen indices and if `closed` is specified then the wildcard expression isexpanded only to closed indices. Also both values (`open,closed`) can bespecified to expand to all indices.+If `none` is specified then wildcard expansion will be disabled and if `all` is specified, wildcard expressions will expand to all indices (this is equivalent to specifying `open,closed`).The defaults settings for the above parameters depend on the api being used.NOTE: Single index APIs such as the <<docs>> and the<<indices-aliases,single-index `alias` APIs>> do not support multiple indices.[[common-options]]== Common optionsThe following options can be applied to all of the REST APIs.[float]=== Pretty ResultsWhen appending `?pretty=true` to any request made, the JSON returnedwill be pretty formatted (use it for debugging only!). Another option isto set `format=yaml` which will cause the result to be returned in the(sometimes) more readable yaml format.[float]=== Human readable outputStatistics are returned in a format suitable for humans(eg `"exists_time": "1h"` or `"size": "1kb"`) and for computers(eg `"exists_time_in_millis": 3600000`` or `"size_in_bytes": 1024`).The human readable values can be turned off by adding `?human=false`to the query string. This makes sense when the stats results arebeing consumed by a monitoring tool, rather than intended for humanconsumption.  The default for the `human` flag is`false`.[float]=== Flat SettingsThe `flat_settings` flag affects rendering of the lists of settings. Whenflat_settings` flag is `true` settings are returned in a flat format:[source,js]--------------------------------------------------{  "persistent" : { },  "transient" : {    "discovery.zen.minimum_master_nodes" : "1"  }}--------------------------------------------------When the `flat_settings` flag is `false` settings are returned in a morehuman readable structured format:[source,js]--------------------------------------------------{  "persistent" : { },  "transient" : {    "discovery" : {      "zen" : {        "minimum_master_nodes" : "1"      }    }  }}--------------------------------------------------By default the `flat_settings` is set to `false`.[float]=== ParametersRest parameters (when using HTTP, map to HTTP URL parameters) follow theconvention of using underscore casing.[float]=== Boolean ValuesAll REST APIs parameters (both request parameters and JSON body) supportproviding boolean "false" as the values: `false`, `0`, `no` and `off`.All other values are considered "true". Note, this is not related tofields within a document indexed treated as boolean fields.[float]=== Number ValuesAll REST APIs support providing numbered parameters as `string` on topof supporting the native JSON number types.[[time-units]][float]=== Time unitsWhenever durations need to be specified, eg for a `timeout` parameter, the durationcan be specified as a whole number representing time in milliseconds, or as a time value like `2d` for 2 days.  The supported units are:[horizontal]`y`::   Year`M`::   Month`w`::   Week`d`::   Day`h`::   Hour`m`::   Minute`s`::   Second[[distance-units]][float]=== Distance UnitsWherever distances need to be specified, such as the `distance` parameter inthe <<query-dsl-geo-distance-filter>>) or the `precision` parameter in the<<query-dsl-geohash-cell-filter>>, the default unit if none is specified isthe meter. Distances can be specified in other units, such as `"1km"` or`"2mi"` (2 miles).The full list of units is listed below:[horizontal]Mile::          `mi` or `miles`Yard::          `yd` or `yards`Feet::          `ft` or `feet`Inch::          `in` or `inch`Kilometer::     `km` or `kilometers`Meter::         `m` or `meters`Centimeter::    `cm` or `centimeters`Millimeter::    `mm` or `millimeters`Nautical mile:: `NM`, `nmi` or `nauticalmiles`[[fuzziness]][float]=== FuzzinessSome queries and APIs support parameters to allow inexact _fuzzy_ matching,using the `fuzziness` parameter. The `fuzziness` parameter is contextsensitive which means that it depends on the type of the field being queried:[float]==== Numeric, date and IPv4 fieldsWhen querying numeric, date and IPv4 fields, `fuzziness` is interpreted as a`+/-` margin. It behaves like a <<query-dsl-range-query>> where:    -fuzziness <= field value <= +fuzzinessThe `fuzziness` parameter should be set to a numeric value, eg `2` or `2.0`. A`date` field interprets a long as milliseconds, but also accepts a stringcontaining a time value -- `"1h"` -- as explained in <<time-units>>. An `ip`field accepts a long or another IPv4 address (which will be converted into along).[float]==== String fieldsWhen querying `string` fields, `fuzziness` is interpreted as ahttp://en.wikipedia.org/wiki/Levenshtein_distance[Levenshtein Edit Distance]-- the number of one character changes that need to be made to one string tomake it the same as another string.The `fuzziness` parameter can be specified as:`0`, `1`, `2`::the maximum allowed Levenshtein Edit Distance (or number of edits)`AUTO`::+--generates an edit distance based on the length of the term. For lengths:`0..1`:: must match exactly`1..4`:: one edit allowed`>4`:: two edits allowed`AUTO` should generally be the preferred value for `fuzziness`.--`0.0..1.0`::converted into an edit distance using the formula: `length(term) * (1.0 -fuzziness)`, eg a `fuzziness` of `0.6` with a term of length 10 would resultin an edit distance of `4`. Note: in all APIs except for the<<query-dsl-flt-query>>, the maximum allowed edit distance is `2`.[float]=== Result CasingAll REST APIs accept the `case` parameter. When set to `camelCase`, allfield names in the result will be returned in camel casing, otherwise,underscore casing will be used. Note, this does not apply to the sourcedocument indexed.[float]=== JSONPBy default JSONP responses are disabled.When enabled, all REST APIs accept a `callback` parameterresulting in a http://en.wikipedia.org/wiki/JSONP[JSONP] result. You can enablethis behavior by adding the following to `config.yaml`:    http.jsonp.enable: truePlease note, when enabled, due to the architecture of Elasticsearch, this may posea security risk. Under some circumstances, an attacker may be able to exfiltratedata in your Elasticsearch server if they're able to force your browser to make aJSONP request on your behalf (e.g. by including a <script> tag on an untrusted sitewith a legitimate query against a local Elasticsearch server).[float]=== Request body in query stringFor libraries that don't accept a request body for non-POST requests,you can pass the request body as the `source` query string parameterinstead.[[url-access-control]]== URL-based access controlMany users use a proxy with URL-based access control to secure access toElasticsearch indices. For <<search-multi-search,multi-search>>,<<docs-multi-get,multi-get>> and <<docs-bulk,bulk>> requests, the user hasthe choice of specifying an index in the URL and on each individual requestwithin the request body. This can make URL-based access control challenging.To prevent the user from overriding the index which has been specified in theURL, add this setting to the `config.yml` file:    rest.action.multi.allow_explicit_index: falseThe default value is `true`, but when set to `false`, Elasticsearch willreject requests that have an explicit index specified in the request body.
 |