I'm writing the following and saving it as a scripted field in elasticsearch
for(name in parsed.FIRST_NAME){
if('Steve' in parsed.FIRST_NAME){
return parsed.FIRST_NAME
}
}
This givse me the error:
Error: Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"compile error","script_stack":["... ST_NAME){\n\n if('Chan' in parsed.FIRST_NAME){\n ..."," ^---- HERE"],"script":"for(name in parsed.FIRST_NAME){\n\n if('Chan' in parsed.FIRST_NAME){\n return parsed.FIRST_NAME\n }\n}","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"somelistcopy","node":"L0V2Tkf7SoeSWwtzU_DK-A","reason":{"type":"script_exception","reason":"compile error","script_stack":["... ST_NAME){\n\n if('Chan' in parsed.FIRST_NAME){\n ..."," ^---- HERE"],"script":"for(name in parsed.FIRST_NAME){\n\n if('Chan' in parsed.FIRST_NAME){\n return parsed.FIRST_NAME\n }\n}","lang":"painless","caused_by": {"type":"illegal_argument_exception","reason":"unexpected token ['in'] was expecting one of [')']."}}}]},"status":500}
at http://localhost:5601/bundles/kibana.bundle.js?v=16108:29:9038
at Function.Promise.try (http://localhost:5601/bundles/commons.bundle.js?v=16108:86:22184)
at http://localhost:5601/bundles/commons.bundle.js?v=16108:86:21568
at Array.map (<anonymous>)
at Function.Promise.map (http://localhost:5601/bundles/commons.bundle.js?v=16108:86:21523)
at callResponseHandlers (http://localhost:5601/bundles/kibana.bundle.js?v=16108:29:8654)
at http://localhost:5601/bundles/kibana.bundle.js?v=16108:28:29176
at processQueue (http://localhost:5601/bundles/commons.bundle.js?v=16108:39:9912)
at http://localhost:5601/bundles/commons.bundle.js?v=16108:39:10805
at Scope.$digest (http://localhost:5601/bundles/commons.bundle.js?v=16108:39:21741)
I then altered my code to the following (note that 'parsed.FIRST_NAME' is the name of the field stored in elasticsearch):
for(int i = 0; i < doc['parsed.FIRST_NAME'].length; ++i){
if(parsed.FIRST_NAME[i] == 'Steve'){
return parsed.FIRST_NAME
}
}
and am now getting this error:
Error: Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"compile error","script_stack":["... '].length; ++i){\n\n if(parsed.FIRST_NAME[i] == ' ..."," ^---- HERE"],"script":"for(int i = 0; i < doc['parsed.FIRST_NAME'].length; ++i){\n\n if(parsed.FIRST_NAME[i] == 'Chan'){\n return parsed.FIRST_NAME\n }\n}","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"somelistcopy","node":"L0V2Tkf7SoeSWwtzU_DK-A","reason":{"type":"script_exception","reason":"compile error","script_stack":["... '].length; ++i){\n\n if(parsed.FIRST_NAME[i] == ' ..."," ^---- HERE"],"script":"for(int i = 0; i < doc['parsed.FIRST_NAME'].length; ++i){\n\n if(parsed.FIRST_NAME[i] == 'Chan'){\n return parsed.FIRST_NAME\n }\n}","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"Variable [parsed] is not defined."}}}]},"status":500}
at http://localhost:5601/bundles/kibana.bundle.js?v=16108:29:9038
at Function.Promise.try (http://localhost:5601/bundles/commons.bundle.js?v=16108:86:22184)
at http://localhost:5601/bundles/commons.bundle.js?v=16108:86:21568
at Array.map (<anonymous>)
at Function.Promise.map (http://localhost:5601/bundles/commons.bundle.js?v=16108:86:21523)
at callResponseHandlers (http://localhost:5601/bundles/kibana.bundle.js?v=16108:29:8654)
at http://localhost:5601/bundles/kibana.bundle.js?v=16108:28:29176
at processQueue (http://localhost:5601/bundles/commons.bundle.js?v=16108:39:9912)
at http://localhost:5601/bundles/commons.bundle.js?v=16108:39:10805
at Scope.$digest (http://localhost:5601/bundles/commons.bundle.js?v=16108:39:21741)
How do I get this script working? I'm not sure what exactly I'm missing here
! Unfortunately I have another issue now. In my index I've pushed data from two different datasets (into one index, as you can't do comparisons across indexes using elasticsearch). The fields from the dataset that are pushed in first become 'missing fields' and when I'm scripting, I'm unable to access them even though I know they're there.