<commit_before>[[create-stored-script-api]]
=== Create or update stored script API
++++
<titleabbrev>Create or update stored script</titleabbrev>
++++

Creates or updates a <<script-stored-scripts,stored script>> or
<<search-template,search template>>.

[source,console]
----
PUT _scripts/my-stored-script
{
  "script": {
    "lang": "painless",
    "source": """
      TimestampHour date =  doc['@timestamp'].value; 
      return date.getHour()
    """
  }
}
----

[[create-stored-script-api-request]]
==== {api-request-title}

`PUT _scripts/<script-id>`

`POST _scripts/<script-id>`

`PUT _scripts/<script-id>/<context>`

`POST _scripts/<script-id>/<context>`

[[create-stored-script-api-prereqs]]
==== {api-prereq-title}

* If the {es} {security-features} are enabled, you must have the `manage`
<<privileges-list-cluster,cluster privilege>> to use this API.

[[create-stored-script-api-path-params]]
==== {api-path-parms-title}

`<script-id>`::
(Required, string)
Name or identifier for the stored script or search template. Must be unique
within the cluster.

`<context>`::<commit_msg>[DOCS] Clarify `<script-id>` parameter def<commit_after>[[create-stored-script-api]]
=== Create or update stored script API
++++
<titleabbrev>Create or update stored script</titleabbrev>
++++

Creates or updates a <<script-stored-scripts,stored script>> or
<<search-template,search template>>.

[source,console]
----
PUT _scripts/my-stored-script
{
  "script": {
    "lang": "painless",
    "source": """
      TimestampHour date =  doc['@timestamp'].value; 
      return date.getHour()
    """
  }
}
----

[[create-stored-script-api-request]]
==== {api-request-title}

`PUT _scripts/<script-id>`

`POST _scripts/<script-id>`

`PUT _scripts/<script-id>/<context>`

`POST _scripts/<script-id>/<context>`

[[create-stored-script-api-prereqs]]
==== {api-prereq-title}

* If the {es} {security-features} are enabled, you must have the `manage`
<<privileges-list-cluster,cluster privilege>> to use this API.

[[create-stored-script-api-path-params]]
==== {api-path-parms-title}

`<script-id>`::
(Required, string)
Identifier for the stored script or search template. Must be unique within the
cluster.

`<context>`::
{'fraction_non_alphanumeric': 0.18673330304407088, 'fraction_numerical': 0.0, 'mean_word_length': 4.477611940298507, 'pattern_counts': {'":': 6, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '531533', 'n_tokens_mistral': 773, 'n_tokens_neox': 744, 'n_words': 169}