{"id":1647,"date":"2022-01-09T11:30:21","date_gmt":"2022-01-09T11:30:21","guid":{"rendered":"https:\/\/multisite.korebots.com\/SearchAssist\/?p=1647"},"modified":"2022-01-18T06:05:12","modified_gmt":"2022-01-18T06:05:12","slug":"how-to-run-custom-scripts","status":"publish","type":"post","link":"https:\/\/multisite.korebots.com\/SearchAssist\/how-to\/how-to-run-custom-scripts\/","title":{"rendered":"How to Run Custom Scripts"},"content":{"rendered":"<section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row via_grid cols_1 laptops-cols_inherit tablets-cols_inherit mobiles-cols_1 valign_top type_default stacking_default\"><div class=\"wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><p><span style=\"font-weight: 400;\">The Custom Script stage in <\/span><a href=\"https:\/\/docs.kore.ai\/SearchAssist\/lifecycle\/manage-index\/workbench\/\"><span style=\"font-weight: 400;\">Indexing Pipeline<\/span><\/a><span style=\"font-weight: 400;\"> 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.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ensure to click\u00a0 <\/span><b>Train your App<\/b><span style=\"font-weight: 400;\"> each time you make changes to any index configuration. This builds the index based on the updated configurations.<a ref=\"magnificPopup\" href=\"https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Train_your_App_icon.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1605 size-full\" src=\"https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Train_your_App_icon.png\" alt=\"\" width=\"460\" height=\"59\" srcset=\"https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Train_your_App_icon.png 460w, https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Train_your_App_icon-300x38.png 300w\" sizes=\"(max-width: 460px) 100vw, 460px\" \/><\/a><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Configuration<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To configure a custom script, take the following steps:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Click the <\/span><b>Indices <\/b><span style=\"font-weight: 400;\">tab on the top.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">On the left pane, under the <\/span><b>Index Configuration<\/b><span style=\"font-weight: 400;\"> section, click <\/span><b>Workbench<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">On the Workbench (Index Configuration) page, on the <\/span><b>Stages <\/b><span style=\"font-weight: 400;\">column, click the <\/span><strong>+<\/strong><span style=\"font-weight: 400;\"> icon.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Select <\/span><b>Custom Script<\/b><span style=\"font-weight: 400;\"> from the <\/span><b>Stage Type<\/b><span style=\"font-weight: 400;\"> dropdown list.<a ref=\"magnificPopup\" href=\"https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Manage_indices_wb_custom-script1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1648 size-medium\" src=\"https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Manage_indices_wb_custom-script1-293x300.png\" alt=\"\" width=\"293\" height=\"300\" srcset=\"https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Manage_indices_wb_custom-script1-293x300.png 293w, https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Manage_indices_wb_custom-script1.png 476w\" sizes=\"(max-width: 293px) 100vw, 293px\" \/><\/a><\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Enter a name in the <\/span><b>Stage Name<\/b><span style=\"font-weight: 400;\"> field.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Enter a condition in the <\/span><b>Condition <\/b><span style=\"font-weight: 400;\">field.\u00a0 Add multiple conditions using the AND\/OR connectors. SearchAssist execudes documents that satisfy the condition(s). See <\/span><a href=\"https:\/\/docs.google.com\/document\/d\/1A1G6RzvrbxqNQtagGPWiBYSm2sIZaKiB\/edit#bookmark=id.vcvaia3fi6wx\"><span style=\"font-weight: 400;\">Conditions for Running Scripts<\/span><\/a><span style=\"font-weight: 400;\"> for details.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Under the <\/span><b>&lt;\/&gt;Painless<\/b><span style=\"font-weight: 400;\"> section, enter the custom script. See the following <\/span><span style=\"font-weight: 400;\">details<\/span><span style=\"font-weight: 400;\">. <a ref=\"magnificPopup\" href=\"https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Manage_indices_wb_custom-script2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1650 size-large\" src=\"https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Manage_indices_wb_custom-script2-1024x489.png\" alt=\"\" width=\"640\" height=\"306\" srcset=\"https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Manage_indices_wb_custom-script2-1024x489.png 1024w, https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Manage_indices_wb_custom-script2-300x143.png 300w, https:\/\/multisite.korebots.com\/SearchAssist\/wp-content\/uploads\/sites\/18\/2021\/12\/Manage_indices_wb_custom-script2.png 1662w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Click <\/span><b>Simulate<\/b><span style=\"font-weight: 400;\"> 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.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Once ready, click <\/span><b>Save Configuration<\/b><span style=\"font-weight: 400;\"> on the upper-right.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Script<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Example<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To copy a value from <\/span><i><span style=\"font-weight: 400;\">\u201cdefaultAnswers[*].payload\u201d<\/span><\/i><span style=\"font-weight: 400;\"> to<\/span><i><span style=\"font-weight: 400;\"> \u201canswer[]\u201d<\/span><\/i><span style=\"font-weight: 400;\">, use the following script:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ctx.answer =[]; for (def item : ctx.defaultAnswers) { ctx.answer.add(item.payload) }<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Conditions for Running Scripts<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Condition is of the following format: <\/span><span style=\"font-weight: 400;\">ctx.fieldtype==value<\/span><span style=\"font-weight: 400;\"> or <\/span><span style=\"font-weight: 400;\">ctx.fieldtype!=value<\/span><span style=\"font-weight: 400;\">. The <\/span><i><span style=\"font-weight: 400;\">field_name<\/span><\/i><span style=\"font-weight: 400;\"> can be obtained from the Fields table under Index Configuration.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, <\/span><span style=\"font-weight: 400;\">ctx.contentType==&#8221;web&#8221;<\/span><span style=\"font-weight: 400;\"> to restrict the extraction to the content from a web source.<\/span><\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div><\/div><\/div><\/div><\/div><\/section><section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row via_grid cols_1 laptops-cols_inherit tablets-cols_inherit mobiles-cols_1 valign_top type_default stacking_default\"><div class=\"wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"w-post-elm post_navigation layout_simple inv_false\"><a class=\"post_navigation-item order_first to_prev\" href=\"https:\/\/multisite.korebots.com\/SearchAssist\/how-to\/how-to-apply-semantic-meanings\/\" title=\"How to Apply Semantic Meanings\"><div class=\"post_navigation-item-arrow\"><\/div><div class=\"post_navigation-item-meta\">Previous Post<\/div><div class=\"post_navigation-item-title\"><span>How to Apply Semantic Meanings<\/span><\/div><\/a><a class=\"post_navigation-item order_second to_next\" href=\"https:\/\/multisite.korebots.com\/SearchAssist\/how-to\/how-to-create-search-configurations\/\" title=\"How to Create Search Configurations\"><div class=\"post_navigation-item-arrow\"><\/div><div class=\"post_navigation-item-meta\">Next Post<\/div><div class=\"post_navigation-item-title\"><span>How to Create Search Configurations<\/span><\/div><\/a><\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"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\u00a0 Train your App each time you make changes to any index configuration. This builds the...","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59,58],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/multisite.korebots.com\/SearchAssist\/wp-json\/wp\/v2\/posts\/1647"}],"collection":[{"href":"https:\/\/multisite.korebots.com\/SearchAssist\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multisite.korebots.com\/SearchAssist\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multisite.korebots.com\/SearchAssist\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/multisite.korebots.com\/SearchAssist\/wp-json\/wp\/v2\/comments?post=1647"}],"version-history":[{"count":5,"href":"https:\/\/multisite.korebots.com\/SearchAssist\/wp-json\/wp\/v2\/posts\/1647\/revisions"}],"predecessor-version":[{"id":2713,"href":"https:\/\/multisite.korebots.com\/SearchAssist\/wp-json\/wp\/v2\/posts\/1647\/revisions\/2713"}],"wp:attachment":[{"href":"https:\/\/multisite.korebots.com\/SearchAssist\/wp-json\/wp\/v2\/media?parent=1647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multisite.korebots.com\/SearchAssist\/wp-json\/wp\/v2\/categories?post=1647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multisite.korebots.com\/SearchAssist\/wp-json\/wp\/v2\/tags?post=1647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}