How to Run Custom Scripts

The Custom Script stage in Indexing Pipeline allows code custom processing. You can write a painless script to perform actions such as adding a new field, deleting a field, setting/resetting values to a field, copying fields, etc.

Ensure to click  Train your App each time you make changes to any index configuration. This builds the index based on the updated configurations.


To configure a custom script, take the following steps:

  1. Click the Indices tab on the top.
  2. On the left pane, under the Index Configuration section, click Workbench.
  3. On the Workbench (Index Configuration) page, on the Stages column, click the + icon.
  4. Select Custom Script from the Stage Type dropdown list.
  5. Enter a name in the Stage Name field. 
  6. Enter a condition in the Condition field.  Add multiple conditions using the AND/OR connectors. SearchAssist execudes documents that satisfy the condition(s). See Conditions for Running Scripts for details.
  7. Under the </>Painless section, enter the custom script. See the following details.
  8. Click Simulate to verify the configurations. The simulator displays the Source and the number of documents to which the mapping was applied, and the result. You can change the Source and the number of documents if there is no mention of it in the conditions.
  9. Once ready, click Save Configuration on the upper-right.



To copy a value from “defaultAnswers[*].payload” to “answer[]”, use the following script:

ctx.answer =[]; for (def item : ctx.defaultAnswers) { ctx.answer.add(item.payload) }

Conditions for Running Scripts

Condition is of the following format: ctx.fieldtype==value or ctx.fieldtype!=value. The field_name can be obtained from the Fields table under Index Configuration.

For example, ctx.contentType==”web” to restrict the extraction to the content from a web source.