f5b2dfd052
Fixes a bug where alias creation would allow `null` for index name, which thereby applied the alias to _all_ indices. This patch makes the validator throw an exception if the index is null. ```bash POST /_aliases { "actions": [ { "add": { "alias": "empty-alias", "index": null } } ] } ``` ```json { "error": "ActionRequestValidationException[Validation Failed: 1: Alias action [add]: [index] may not be null;]", "status": 400 } ``` The reason this bug wasn't caught by the existing tests is because the old test for nullness only validated against a cluster which had zero indices. The null index is translated into "_all", and since there are no indices, this fails because the index doesn't exist. So the test passes. However, as soon as you add an index, "_all" resolves and you get the situation described in the original bug report: null index is accepted by the alias, resolves to "_all" and gets applied to everything. The REST tests, otoh, explicitly tested this bug as a real feature and therefore passed. The REST tests were modified to change this behavior. Fixes #7863 |
||
---|---|---|
.. | ||
api | ||
test | ||
utils | ||
.gitignore | ||
LICENSE.txt | ||
README.markdown |
README.markdown
Elasticsearch REST API JSON specification
This repository contains a collection of JSON files which describe the Elasticsearch HTTP API.
Their purpose is to formalize and standardize the API, to facilitate development of libraries and integrations.
Example for the "Create Index" API:
{
"indices.create": {
"documentation": "http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/",
"methods": ["PUT", "POST"],
"url": {
"path": "/{index}",
"paths": ["/{index}"],
"parts": {
"index": {
"type" : "string",
"required" : true,
"description" : "The name of the index"
}
},
"params": {
"timeout": {
"type" : "time",
"description" : "Explicit operation timeout"
}
}
},
"body": {
"description" : "The configuration for the index (`settings` and `mappings`)"
}
}
}
The specification contains:
- The name of the API (
indices.create
), which usually corresponds to the client calls - Link to the documentation at http://elasticsearch.org
- List of HTTP methods for the endpoint
- URL specification: path, parts, parameters
- Whether body is allowed for the endpoint or not and its description
The methods
and url.paths
elements list all possible HTTP methods and URLs for the endpoint;
it is the responsibility of the developer to use this information for a sensible API on the target platform.
Utilities
The repository contains some utilities in the utils
directory:
- The
thor api:generate:spec
will generate the basic JSON specification from Java source code - The
thor api:generate:code
generates Ruby source code and tests from the specs, and can be extended to generate assets in another programming language
Run bundle install
and then thor list
in the utils folder.
The full command to generate the api spec is:
thor api:spec:generate --output=myfolder --elasticsearch=/path/to/es
License
This software is licensed under the Apache 2 license.