Add Runtime field to change Mapping of a Field

Hi everyone!
I need to change the mapping of a current field because is currentry a text field and i need to be a keyword.
The field path is event.userDefined.headerId
The currentry mapping has some dynamic templates:

          "userdefined-string": {
            "path_match": "event.userDefined.*",
            "match_mapping_type": "string",
            "mapping": {
              "type": "text"
            }
          }
        },
        {
          "userdefined-long": {
            "path_match": "event.userDefined.*",
            "match_mapping_type": "long",
            "mapping": {
              "type": "integer"
            }
          }
        }

and i need to change the field header id inside event.userDefined to keyword

"userDefined": {
  "parameters": {
    "properties": {
      "error_code": {
      "type": "text"
      },
      "error_description": {
      "type": "text"
      },
      "headerId": {
      "type": "text"
      }
    }
    },
    "query": {
    "type": "text"
    }
  }
}

I created the following runtime field to do that but is not currently working

"runtime": {
      "event.userDefined.headerId": {
        "type": "keyword",
        "script": {
          "source": "emit(doc['event.userDefined.headerId'].value)",
          "lang": "painless"
        }
      }
    },e

Please help

Thanks in advance

Hello
You can not change the mapping of already indexed documents you will have to reindex them

I think you can do something like:

"runtime": {
      "event.userDefined.headerId.keyword": {
        "type": "keyword",
        "script": {
          "source": "emit(doc['event.userDefined.headerId'].value)",
          "lang": "painless"
        }
      }
    },

And then run your queries/aggs against event.userDefined.headerId.keyword.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.