Hello,
I'm having issues with runtime fields with Elastic. I have this run time field working fine in Kibana, however, I need this field to be present in the database. I simplified the script, mostly to redact it's sensitive content and I'm able to duplicate it. What I am trying to do, is create a new run time field based on a keyword match to emit a keyword value.
PUT test_index
{
"mappings": {
"properties": {
"dept_code": {
"type": "keyword"}
}
}
}
POST test_index/_bulk
{"index":{"_id":"1"}}
{"dept_code":"999"}
{"index":{"_id":"2"}}
{"dept_code":"998"}
PUT test_index/_mapping
{
"mappings": {
"runtime": {
"test_script": {
"type": "keyword",
"script": {
"source": "if (doc['dept_code.keyword'].contains('999')) emit('match_999'); if (doc['dept_code.keyword'].contains('998')) emit('match_998');"
}
}
}
}
}
When I apply the run time field, I receive the following error:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Root mapping definition has unsupported parameters: [mappings : {runtime={test_script={type=keyword, script={source=if (doc['dept_code.keyword'].contains('999')) emit('match_999'); if (doc['dept_code.keyword'].contains('998')) emit('match_998');}}}}]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping: Root mapping definition has unsupported parameters: [mappings : {runtime={test_script={type=keyword, script={source=if (doc['dept_code.keyword'].contains('999')) emit('match_999'); if (doc['dept_code.keyword'].contains('998')) emit('match_998');}}}}]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "Root mapping definition has unsupported parameters: [mappings : {runtime={test_script={type=keyword, script={source=if (doc['dept_code.keyword'].contains('999')) emit('match_999'); if (doc['dept_code.keyword'].contains('998')) emit('match_998');}}}}]"
}
},
"status": 400
}
Not sure what I'm doing wrong. The script is simple enough.
Thanks for any assistance you can provide.