All methods and paths for this operation:
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.
Values are painless_test, filter, score, boolean_field, date_field, double_field, geo_point_field, ip_field, keyword_field, long_field, or composite_field.
Document that's temporarily indexed in-memory and accessible from the script.
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
Defines the aggregations that are run as part of the search request.
If true, the request returns detailed information about score computation as part of a hit.
Default value is false.
Configuration of search extensions defined by Elasticsearch plugins.
The starting document offset, which must be non-negative.
By default, you cannot page through more than 10,000 hits using the from and size parameters.
To page through more hits, use the search_after parameter.
Default value is 0.
A string that contains each boundary character.
Default value is .,!? \t\n.
How far to scan for boundary characters.
Default value is 20.
Values are chars, sentence, or word.
Controls which locale is used to search for sentence and word boundaries.
This parameter takes a form of a language tag, for example: "en-US", "fr-FR", "ja-JP".
Default value is Locale.ROOT.
Values are simple or span.
The size of the highlighted fragment in characters.
Default value is 100.
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
If set to a non-negative value, highlighting stops at this defined maximum limit.
The rest of the text is not processed, thus not highlighted and no error is returned
The max_analyzed_offset query setting does not override the index.highlight.max_analyzed_offset setting, which prevails when it’s set to lower value than the query setting.
The amount of text you want to return from the beginning of the field if there are no matching fragments to highlight.
Default value is 0.
The maximum number of fragments to return.
If the number of fragments is set to 0, no fragments are returned.
Instead, the entire field contents are highlighted and returned.
This can be handy when you need to highlight short texts such as a title or address, but fragmentation is not required.
If number_of_fragments is 0, fragment_size is ignored.
Default value is 5.
Value is score.
Controls the number of matching phrases in a document that are considered.
Prevents the fvh highlighter from analyzing too many phrases and consuming too much memory.
When using matched_fields, phrase_limit phrases per matched field are considered. Raising the limit increases query time and consumes more memory.
Only supported by the fvh highlighter.
Default value is 256.
Use in conjunction with pre_tags to define the HTML tags to use for the highlighted text.
By default, highlighted text is wrapped in <em> and </em> tags.
Use in conjunction with post_tags to define the HTML tags to use for the highlighted text.
By default, highlighted text is wrapped in <em> and </em> tags.
By default, only fields that contains a query match are highlighted.
Set to false to highlight all fields.
Default value is true.
Value is styled.
Values are default or html.
Number of hits matching the query to count accurately. If true, the exact number of hits is returned at the cost of some performance. If false, the response does not include the total number of hits matching the query. Defaults to 10,000 hits.
Boost the _score of documents from specified indices.
The boost value is the factor by which scores are multiplied.
A boost value greater than 1.0 increases the score.
A boost value between 0 and 1.0 decreases the score.
An array of wildcard (*) field patterns.
The request returns doc values for field names matching these patterns in the hits.fields property of the response.
A reference to a field with formatting instructions on how to return the value
The approximate kNN search to run.
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
The final number of nearest neighbors to return as top hits
The number of nearest neighbor candidates to consider per shard
Boost value to apply to kNN scores
The minimum similarity for a vector to be considered a match
The maximum number of hits to return per inner_hits.
Default value is 3.
Inner hit starting document offset.
Default value is 0.
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
Default value is false.
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
The final number of nearest neighbors to return as top hits
The number of nearest neighbor candidates to consider per shard
Boost value to apply to kNN scores
The minimum similarity for a vector to be considered a match
The minimum _score for matching documents.
Documents with a lower _score are not included in search results or results collected by aggregations.
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
Set to true to return detailed timing information about the execution of individual components in a search request.
NOTE: This is a debugging tool and adds significant overhead to search execution.
Default value is false.
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
Retriever name.
An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
A field value.
Maximum number of documents to collect for each shard.
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
Retriever name.
The name of the vector field to search against.
Number of nearest neighbors to return as top hits.
Number of nearest neighbor candidates to consider per shard.
The minimum similarity required for a document to be considered a match.
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
Retriever name.
A list of child retrievers to specify which sets of returned top documents will have the RRF formula applied to them.
This value determines how much influence documents in individual result sets per query have over the final ranked result set.
This value determines the size of the individual result sets per query.
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
Retriever name.
This value determines how many documents we will consider from the nested retriever.
Unique identifier of the inference endpoint created using the inference API.
The text snippet used as the basis for similarity comparison
The document field to be used for text similarity comparisons. This field should contain the text that will be evaluated against the inference_text
Minimum _score for matching documents. Documents with a lower _score are not included in the top documents.
Retriever name.
The match criteria that will determine if a rule in the provided rulesets should be applied.
This value determines the size of the individual result set.
Retrieve a script evaluation (based on different fields) for each hit.
A field value.
The number of hits to return, which must not be negative.
By default, you cannot page through more than 10,000 hits using the from and size parameters.
To page through more hits, use the search_after property.
Default value is 10.
An array of wildcard (*) field patterns.
The request returns values for field names matching these patterns in the hits.fields property of the response.
A reference to a field with formatting instructions on how to return the value
The maximum number of documents to collect for each shard. If a query reaches this limit, Elasticsearch terminates the query early. Elasticsearch collects documents before sorting.
IMPORTANT: Use with caution. Elasticsearch applies this property to each shard handling the request. When possible, let Elasticsearch perform early termination automatically. Avoid specifying this property for requests that target data streams with backing indices across multiple data tiers.
If set to 0 (default), the query does not terminate early.
Default value is 0.
The period of time to wait for a response from each shard. If no response is received before the timeout expires, the request fails and returns an error. Defaults to no timeout.
If true, calculate and return document scores, even if the scores are not used for sorting.
Default value is false.
If true, the request returns the document version as part of a hit.
Default value is false.
If true, the request returns sequence number and primary term of the last modification of each hit.
For type composite
For type lookup
A custom format for date type runtime fields.
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
Values are boolean, composite, date, double, geo_point, geo_shape, ip, keyword, long, or lookup.
The stats groups to associate with the search. Each group maintains a statistics aggregation for its associated searches. You can retrieve these stats using the indices stats API.
Specifies any named parameters that are passed into the script as variables. Use parameters instead of hard-coded values to decrease compile time.
POST /_scripts/painless/_execute
{
"script": {
"source": "params.count / params.total",
"params": {
"count": 100.0,
"total": 1000.0
}
}
}
resp = client.scripts_painless_execute(
script={
"source": "params.count / params.total",
"params": {
"count": 100,
"total": 1000
}
},
)
const response = await client.scriptsPainlessExecute({
script: {
source: "params.count / params.total",
params: {
count: 100,
total: 1000,
},
},
});
response = client.scripts_painless_execute(
body: {
"script": {
"source": "params.count / params.total",
"params": {
"count": 100,
"total": 1000
}
}
}
)
$resp = $client->scriptsPainlessExecute([
"body" => [
"script" => [
"source" => "params.count / params.total",
"params" => [
"count" => 100,
"total" => 1000,
],
],
],
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"script":{"source":"params.count / params.total","params":{"count":100,"total":1000}}}' "$ELASTICSEARCH_URL/_scripts/painless/_execute"
client.scriptsPainlessExecute(s -> s
.script(sc -> sc
.source(so -> so
.scriptString("params.count / params.total")
)
.params(Map.of("total", JsonData.fromJson("1000"),"count", JsonData.fromJson("100")))
)
);
{
"script": {
"source": "params.count / params.total",
"params": {
"count": 100.0,
"total": 1000.0
}
}
}
{
"script": {
"source": "doc['field'].value.length() <= params.max_length",
"params": {
"max_length": 4
}
},
"context": "filter",
"context_setup": {
"index": "my-index-000001",
"document": {
"field": "four"
}
}
}
{
"script": {
"source": "doc['rank'].value / params.max_rank",
"params": {
"max_rank": 5.0
}
},
"context": "score",
"context_setup": {
"index": "my-index-000001",
"document": {
"rank": 4
}
}
}
{
"result": "0.1"
}
{
"result": true
}
{
"result": 0.8
}