[DOC] Get _scripts API does not work
What do you want to do?
- [x] Request a change to existing documentation
- [ ] Add new documentation
- [x] Report a technical problem with the documentation
- [ ] Other
Tell us about your request. Provide a summary of the request.
If we look at the scripts API here https://opensearch.org/docs/latest/api-reference/script-apis/get-stored-script/, it says we can use GET _scripts/my-first-script to retrieve a script but this throws an error
{
"error": {
"root_cause": [
{
"type": "invalid_index_name_exception",
"reason": "Invalid index name [_scripts], must not start with '_'.",
"index": "_scripts",
"index_uuid": "_na_"
}
],
"type": "invalid_index_name_exception",
"reason": "Invalid index name [_scripts], must not start with '_'.",
"index": "_scripts",
"index_uuid": "_na_"
},
"status": 400
}
Instead, we have to use GET _cluster/state/metadata?filter_path=metadata.stored_scripts to get the script. The document should mention this
Version: List the OpenSearch version to which this issue applies, e.g. 2.14, 2.12--2.14, or all.
What other resources are available? Provide links to related issues, POCs, steps for testing, etc.
@prabhupant: I think the example assumes that a script named my-first-script exists within the cluster. I'll update the endpoint at the top to use a generic
@prabhupant Here's a complete example:
PUT _scripts/my-first-script
{
"script": {
"lang": "painless",
"source": """
int total = 0;
for (int i = 0; i < doc['ratings'].length; ++i) {
total += doc['ratings'][i];
}
return total;
"""
}
}
GET _scripts/my-first-script