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

# Get a script or search template

## 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`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## 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)
    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` (union)
    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"
)
```

