I am attempting to create a new scripted field assignee.role where there may be thousands of possibilities, but only want to make it defined for a subset of the possibilities, how do I lump everyone else into the undefined group?
//
<
if(doc['assigneename.keyword'].value == 'mike') {
return "Generalist";
} else if(doc['assigneename.keyword'].value == 'bill') {
return "Generalist";
} else if(doc['assigneename.keyword'].value == 'josh') {
return "Generalist";
} else if(doc['assigneename.keyword'].value == 'sam') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'blake') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'bob') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'jake') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'amy') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'frank') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'brian') {
return "SME";
} else if(doc['assigneename.keyword'].value == '') {
return "undefined";
/>
spalger
(Spencer Alger)
May 1, 2018, 9:16pm
2
You can probably just add else { return "my other group" }
to the end
so someething like this? I seem to get an error when doing so
<
if(doc['assigneename.keyword'].value == 'jim') {
return "Generalist";
} else if(doc['assigneename.keyword'].value == 'bill') {
return "Generalist";
} else if(doc['assigneename.keyword'].value == 'josh') {
return "Generalist";
} else if(doc['assigneename.keyword'].value == 'sam') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'blake') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'bob') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'jake') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'amy') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'frank') {
return "SME";
} else if(doc['assigneename.keyword'].value == 'brian') {
return "SME";
} else {
return "undefined";
}
/>
spalger
(Spencer Alger)
May 2, 2018, 4:46am
4
What error are you receiving?
Error: Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"compile error","script_stack":["... {\n return \"undefined\";"," ^---- HERE"],"script":"if(doc['assigneename.keyword'].value == 'jim') {\n return \"Generalist\";\n } else if(doc['assigneename.keyword'].value == 'helen') {\n return \"Generalist\";\n } else if(doc['assigneename.keyword'].value == 'mark') {\n return \"Generalist\";\n } else if(doc['assigneename.keyword'].value == 'frank') {\n return \"SME\";\n } else if(doc['assigneename.keyword'].value == 'jake') {\n return \"SME\";\n } else if(doc['assigneename.keyword'].value == 'bill') {\n return \"SME\";\n } else if(doc['assigneename.keyword'].value == 'josh') {\n return \"SME\";\t\n } else if(doc['assigneename.keyword'].value == 'bob') {\n return \"SME\";\t\n } else if(doc['assigneename.keyword'].value == 'steve') {\n return \"SME\";\t\n } else if(doc['assigneename.keyword'].value == 'sam') {\n return \"SME\";\n } else if(doc['assigneename.keyword'].value == '') {\n return \"undefined\";","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"doc-itsm-im","node":"yguTWglBReCEOSRjIJx00w","reason":{"type":"script_exception","reason":"compile error","script_stack":["... {\n return \"undefined\";"," ^---- HERE"],"script":"if(doc['assigneename.keyword'].value == 'jim') {\n return \"Generalist\";\n } else if(doc['assigneename.keyword'].value == 'helen') {\n return \"Generalist\";\n } else if(doc['assigneename.keyword'].value == 'mark') {\n return \"Generalist\";\n } else if(doc['assigneename.keyword'].value == 'frank') {\n return \"SME\";\n } else if(doc['assigneename.keyword'].value == 'jake') {\n return \"SME\";\n } else if(doc['assigneename.keyword'].value == 'bill') {\n return \"SME\";\n } else if(doc['assigneename.keyword'].value == 'josh') {\n return \"SME\";\t\n } else if(doc['assigneename.keyword'].value == 'bob') {\n return \"SME\";\t\n } else if(doc['assigneename.keyword'].value == 'steve') {\n return \"SME\";\t\n } else if(doc['assigneename.keyword'].value == 'sam') {\n return \"SME\";\n } else if(doc['assigneename.keyword'].value == '') {\n return \"undefined\";","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"unexpected token ['<EOF>'] was expecting one of ['}']."}}}]},"status":500}
at kibana/bundles/kibana.bundle.js?v=15555:237:1333
at Function.Promise.try (kibana/bundles/commons.bundle.js?v=15555:91:24383)
at kibana/bundles/commons.bundle.js?v=15555:91:23753
at Array.map (<anonymous>)
at Function.Promise.map (kibana/bundles/commons.bundle.js?v=15555:91:23708)
at callResponseHandlers (kibana/bundles/kibana.bundle.js?v=15555:237:949)
at kibana/bundles/kibana.bundle.js?v=15555:236:20482
at processQueue (kibana/bundles/commons.bundle.js?v=15555:38:23621)
at kibana/bundles/commons.bundle.js?v=15555:38:23888
at Scope.$eval (kibana/bundles/commons.bundle.js?v=15555:39:4619)
at Scope.$digest (kibana/bundles/commons.bundle.js?v=15555:39:2359)
at Scope.$apply (kibana/bundles/commons.bundle.js?v=15555:39:5037)
at done (kibana/bundles/commons.bundle.js?v=15555:37:25027)
at completeRequest (kibana/bundles/commons.bundle.js?v=15555:37:28702)
at XMLHttpRequest.xhr.onload (kibana/bundles/commons.bundle.js?v=15555:37:29634)
spalger
(Spencer Alger)
May 2, 2018, 6:45pm
6
Looks like elasticsearch isn't getting the closing }
curly bracket.
Seems like I have all the right brackets
spalger
(Spencer Alger)
May 2, 2018, 7:54pm
8
Can you send a screenshot of the script in Kibana? The source Elasticsearch returns in the error message definitely doesn't have one after return "undefined";
Seems to work now... seems like a bad indentation caused it. Thanks!
system
(system)
Closed
May 31, 2018, 8:09pm
11
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.