Here is what I did. I have only text field for Gender.
"Gender":{
"type":"text"
}
I want to add a keyword sub field to it. I update mapping as
"Gender": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
I use this script to set keyword sub field. Updating the main field automatically updates all its sub-fields.
ctx._source.Gender = ctx._source.Gender.text;