AuthThe Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.AvailabilityExperimentalThis functionality is experimental and is not ready for production usage. Experimental features may change or be removed at any time. Elastic will work to fix any issues, but experimental features are not subject to the support SLA of official GA features. Specific Support terms apply.Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Runs a script and returns a result.
Use this API to build and test scripts, such as when defining a script for a runtime field.
This API requires very few dependencies and is especially useful if you don't have permissions to write documents on a cluster.
The API uses several contexts, which control how scripts are run, what variables are available at runtime, and what the return type is.
Each context requires a script, but additional parameters depend on the context you're using for that script.
The context that the script should run in.
NOTE: Result ordering in the field contexts is not guaranteed.
Supported values include:
painless_test: The default context if no other context is specified.
filter: Treats scripts as if they were run inside a script query.
score: Treats scripts as if they were run inside a script_score function in a function_score query.
boolean_field: The context for boolean fields. The script returns a true or false response.
date_field: The context for date fields. emit takes a long value and the script returns a sorted list of dates.
double_field: The context for double numeric fields. The script returns a sorted list of double values.
geo_point_field: The context for geo-point fields. emit takes two double parameters, the latitude and longitude values, and the script returns an object in GeoJSON format containing the coordinates for the geo point.
ip_field: The context for ip fields. The script returns a sorted list of IP addresses.
keyword_field: The context for keyword fields. The script returns a sorted list of string values.
long_field: The context for long numeric fields. The script returns a sorted list of long values.
composite_field: The context for composite runtime fields. The script returns a map of values.
Additional parameters for the context.
NOTE: This parameter is required for all contexts except painless_test, which is the default if no value is provided for context.
documentobjectrequired
Document that's temporarily indexed in-memory and accessible from the script.
indexstringrequired
Index containing a mapping that's compatible with the indexed document.
You may specify a remote index by prefixing the index with the remote cluster alias.
For example, remote1:my_index indicates that you want to run the painless script against the "my_index" index on the "remote1" cluster.
This request will be forwarded to the "remote1" cluster if you have configured a connection to that remote cluster.
Note
Wildcards are not accepted in the index expression for this endpoint.
The expression *:myindex will return the error "No such remote cluster" and the expression logs* or remote1:logs* will return the error "index not found".