OpenSearch provides several ways to run a script; the following sections show how to run a script by passing script information in the request body of a request.
Sample request
The script’s target is the
books
index.The
total_ratings
field value is the result of themy-first-script
execution. See Create or update stored script.
Sample response
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"total" : {
"value" : 3,
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "books",
"_id" : "1",
"_score" : 1.0,
"fields" : {
"total_ratings" : [
12
]
}
},
{
"_index" : "books",
"_score" : 1.0,
"fields" : {
15
]
}
},
{
"_index" : "books",
"_id" : "3",
"_score" : 1.0,
"fields" : {
"total_ratings" : [
8
]
}
}
]
}