---
type: api
title: Get a script or search template
description: Retrieves a stored script or search template.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-get-script
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-get-script
products:
  - Elasticsearch
---

# Get a script or search template

Availability:

## Paths

- `GET` `/_scripts/{id}`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#bearerauth)

#### Path Parameters

- `id` (string Id)
  The identifier for the stored script or search template.

## Description

Retrieves a stored script or search template.

## Required authorization

* Cluster privileges: `manage`

## Query String Parameters

- `master_timeout` (string Duration · default: 30s)
  The period to wait for the master node.
If the master node is not available before the timeout expires, the request fails and returns an error.
It can also be set to `-1` to indicate that the request should never timeout.

## Response

`application/json`

- `_id` (string Id)
- `found` (boolean)
- `script` ({} StoredScript)
  - `lang` (ScriptLanguage)
    The language the script is written in.
For search templates, use `mustache`.

Supported values include:
  - `painless`: Painless scripting language, purpose-built for Elasticsearch.
  - `expression`: Lucene’s expressions language, compiles a JavaScript expression to bytecode.
  - `mustache`: Mustache templated, used for templates.
  - `java`: Expert Java API
    Values: `painless`, `expression`, `mustache`, `java`
  - `options` (map string to string)
  - `source` (ScriptSource)
    The script source.
For search templates, an object containing the search template.
## Code Examples

#### Console

```console
GET _scripts/my-search-template
```

#### JavaScript

```javascript
const response = await client.getScript({
  id: "my-search-template",
});
```

#### Python

```python
resp = client.get_script(
    id="my-search-template",
)
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_scripts/my-search-template" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.getScript(g -> g
    .id("my-search-template")
);
```

#### C#

```c#
var response = await client.GetScriptAsync(id: "my-search-template");
```

#### PHP

```php
$resp = $client->getScript([
    "id" => "my-search-template",
]);
```

#### Ruby

```ruby
response = client.get_script(
  id: "my-search-template"
)
```

