---
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/4641/api/doc/elasticsearch/v8/operation/operation-get-script
resource: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/elasticsearch/v8/operation/operation-get-script
products:
  - Elasticsearch
---

# Get a script or search template

Authentication: required

## Paths

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

#### Path parameters

- `id` (string) — required
  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 · default: 30s) — optional
  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)
- `found` (boolean)
- `script` (object)
  - `lang` (union anyOf)
    The language the script is written in.
For serach 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` (string)
    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"
)
```

## Response examples

#### 200

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "_id": "string",
  "found": false,
  "script": {
    "lang": "painless",
    "options": {
      "key": "string"
    },
    "source": "string"
  }
}
```

