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 the my-first-script execution. See Create or update stored script.

    Sample response

    1. {
    2. "took" : 2,
    3. "timed_out" : false,
    4. "_shards" : {
    5. "total" : 1,
    6. "successful" : 1,
    7. "skipped" : 0,
    8. "failed" : 0
    9. },
    10. "total" : {
    11. "value" : 3,
    12. },
    13. "max_score" : 1.0,
    14. "hits" : [
    15. {
    16. "_index" : "books",
    17. "_id" : "1",
    18. "_score" : 1.0,
    19. "fields" : {
    20. "total_ratings" : [
    21. 12
    22. ]
    23. }
    24. },
    25. {
    26. "_index" : "books",
    27. "_score" : 1.0,
    28. "fields" : {
    29. 15
    30. ]
    31. }
    32. },
    33. {
    34. "_index" : "books",
    35. "_id" : "3",
    36. "_score" : 1.0,
    37. "fields" : {
    38. "total_ratings" : [
    39. 8
    40. ]
    41. }
    42. }
    43. ]
    44. }

    Response fields

    Hits object

    Document object