resume mapping
PUT resume
{
"mappings":{
"properties":{
"job_experience":{
"type": "nested",
"properties": {
"company": {
"type": "text",
"fielddata":true
}
"end_date": {
"type":"date",
"format":"MM-yyyy"
},
"start_date": {
"type": "date",
"format": "MM-yyyy"
}
}
}
}
}
}
Resume entry
{
"name" : "HOLLY CONNOR",
"job_experience" : [
{
"company" : "lumiminds",
"start_date" : "01-2015",
"end_date" : "01-2019"
},
{
"company" : "asus",
"start_date" : "01-2010",
"end_date" : "12-2014"
}
]
}
Query with script to check if the working experience in a particular company is more than 4 years
POST /resume/_search
{
"query": {
"nested": {
"path": "job_experience",
"query": {
"bool": {
"must": [
{
"match_phrase":{"job_experience.company":"lumiminds"}
},
{
"script":{
"script":" return((doc['job_experience.end_date'].value.year - doc['job_experience.start_date'].value.year) >=4)"
}
}
]
}
}
}
}
}
The above script is working fine until I added "explain":true, to the query
POST /resume/_search
{
"explain":true,
"query": {
"nested": {
"path": "job_experience",
"query": {
"bool": {
"must": [
{
"match_phrase":{"job_experience.company":"lumiminds"}
},
{
"script":{
"script":" return((doc['job_experience.end_date'].value.year - doc['job_experience.start_date'].value.year) >=4)"
}
}
]
}
}
}
}
}
The Error that I received is
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.index.fielddata.ScriptDocValues$Dates.get(ScriptDocValues.java:160)",
"org.elasticsearch.index.fielddata.ScriptDocValues$Dates.getValue(ScriptDocValues.java:154)",
"return((doc['job_experience.end_date'].value.year - doc['job_experience.start_date'].value.year) >=4)",
" ^---- HERE"
],
"script": " return((doc['job_experience.end_date'].value.year - doc['job_experience.start_date'].value.year) >=4)",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "resume",
"node": "qv8i6kpiRmKVGQ3-uvNBOA",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.index.fielddata.ScriptDocValues$Dates.get(ScriptDocValues.java:160)",
"org.elasticsearch.index.fielddata.ScriptDocValues$Dates.getValue(ScriptDocValues.java:154)",
"return((doc['job_experience.end_date'].value.year - doc['job_experience.start_date'].value.year) >=4)",
" ^---- HERE"
],
"script": " return((doc['job_experience.end_date'].value.year - doc['job_experience.start_date'].value.year) >=4)",
"lang": "painless",
"caused_by": {
"type": "illegal_state_exception",
"reason": "A document doesn't have a value for a field! Use doc[<field>].size()==0 to check if a document is missing a field!"
}
}
}
]
},
"status": 400
}
Please help me with the issue. I need to use explain because the full query that i needed is quite complex and I need to explain which search terms matches. Need to get explain and painless script working together.
Thanks