| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 | [[api-conventions]]= API Conventions[partintro]--The *elasticsearch* REST APIs are exposed using <<modules-http,JSON over HTTP>>.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. Thissettings also applies for aliases, in case an alias points to a closed index.`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 equivalentto 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]=== Response FilteringAll REST APIs accept a `filter_path` parameter that can be used to reducethe response returned by elasticsearch. This parameter takes a commaseparated list of filters expressed with the dot notation:[source,sh]--------------------------------------------------curl -XGET 'localhost:9200/_search?pretty&filter_path=took,hits.hits._id,hits.hits._score'{  "took" : 3,  "hits" : {    "hits" : [      {        "_id" : "3640",        "_score" : 1.0      },      {        "_id" : "3642",        "_score" : 1.0      }    ]  }}--------------------------------------------------It also supports the `*` wildcard character to match any field or partof a field's name:[source,sh]--------------------------------------------------curl -XGET 'localhost:9200/_nodes/stats?filter_path=nodes.*.ho*'{  "nodes" : {    "lvJHed8uQQu4brS-SXKsNA" : {      "host" : "portable"    }  }}--------------------------------------------------And the `**` wildcard can be used to include fields without knowing theexact path of the field. For example, we can return the Lucene versionof every segment with this request:[source,sh]--------------------------------------------------curl 'localhost:9200/_segments?pretty&filter_path=indices.**.version'{  "indices" : {    "movies" : {      "shards" : {        "0" : [ {          "segments" : {            "_0" : {              "version" : "5.2.0"            }          }        } ],        "2" : [ {          "segments" : {            "_0" : {              "version" : "5.2.0"            }          }        } ]      }    },    "books" : {      "shards" : {        "0" : [ {          "segments" : {            "_0" : {              "version" : "5.2.0"            }          }        } ]      }    }  }}--------------------------------------------------Note that elasticsearch sometimes returns directly the raw value of a field,like the `_source` field. If you want to filter _source fields, you shouldconsider combining the already existing `_source` parameter (see<<get-source-filtering,Get API>> for more details) with the `filter_path` parameter like this:[source,sh]--------------------------------------------------curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source&_source=title'{  "hits" : {    "hits" : [ {      "_source":{"title":"Book #2"}    }, {      "_source":{"title":"Book #1"}    }, {      "_source":{"title":"Book #3"}    } ]  }}--------------------------------------------------[float]=== Flat SettingsThe `flat_settings` flag affects rendering of the lists of settings. When`flat_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-query>>), 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`The `precision` parameter in the <<query-dsl-geohash-cell-query>> acceptsdistances with the above units, but if no unit is specified, then theprecision is interpreted as the length of the geohash.[[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..2`:: must match exactly`3..5`:: one edit allowed`>5`:: 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 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]=== 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.
 |