Script processor

The script search request processor intercepts a search request and adds an inline Painless script that is run on incoming requests. The script can only run on the following request fields:

  • from
  • size
  • explain
  • version
  • seq_no_primary_term
  • track_scores
  • track_total_hits
  • min_score
  • terminate_after
  • profile

For request field definitions, see search request fields.

Request fields

The following table lists all available request fields.

FieldData typeDescription
sourceInline scriptThe script to run. Required.
langStringThe script language. Optional. Only painless is supported.
tagStringThe processor’s identifier. Optional.
descriptionStringA description of the processor. Optional.
ignore_failureBooleanIf true, OpenSearch ignores any failure of this processor and continues to run the remaining processors in the search pipeline. Optional. Default is false.

Example

The following request creates a search pipeline with a script request processor. The script limits score explanation to only one document because explain is an expensive operation:

  1. PUT /_search/pipeline/explain_one_result
  2. {
  3. "description": "A pipeline to limit the explain operation to one result only",
  4. "request_processors": [
  5. {
  6. "script": {
  7. "lang": "painless",
  8. "source": "if (ctx._source['size'] > 1) { ctx._source['explain'] = false } else { ctx._source['explain'] = true }"
  9. }
  10. }
  11. ]
  12. }

copy