I need to verify whether a candidate’s total experience is zero before returning any associated documents or data. Conversely, if the total experience is not zero, I want to retrieve the documents. Despite my attempts to access this information using various parameters such as params._source.total_experiences, ctx._source.total_experiences, and doc[‘total_experiences’], none of these methods have yielded the desired results. It seems that the mechanism to retrieve this data is not functioning correctly in any of these scenarios. Hence, I seek alternative solutions to effectively ascertain and act upon the total experience value as per the specified criteria.
Here is my query
GET enriched_scraped_profiles/_search
{
"_source": true,
"size": 2000,
"query": {
"bool": {
"must": [
{
"match": {
"experiences.industry": "Banking"
}
}
],
"filter": {
"script": {
"script": {
"lang": "painless",
"source": """
if (params['_source']['total_experiences'] != 0) {
return true;
}
return false;
"""
}
}
}
}
}
}
But I got this error:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"if (params['_source']['total_experiences'] != 0) {n ",
" ^---- HERE"
],
"script": " ...",
"lang": "painless",
"position": {
"offset": 27,
"start": 17,
"end": 86
}
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "enriched_scraped_profiles",
"node": "je5hZrUORgWk9EEmuHQ9rQ",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"if (params['_source']['total_experiences'] != 0) {n ",
" ^---- HERE"
],
"script": " ...",
"lang": "painless",
"position": {
"offset": 27,
"start": 17,
"end": 86
},
"caused_by": {
"type": "null_pointer_exception",
"reason": "Cannot invoke "Object.getClass()" because "callArgs[0]" is null"
}
}
}
]
},
"status": 400
}