0
votes

I'm using Elasticsearch alias fields to rename some fields in my mapping without needing to reindex everything. Works great. Now I want to rename some multi fields as well, like this:

"message":{
  "type":"text",
  "fields":{
    "raw":{
      "type":"keyword"
    }
  }
}

That's an analyzed field named message and a keyword version named message.raw. I can make an alias for message like this:

"title":{
  "type":"alias",
  "path":"message"
}

But I cannot seem to figure out how to alias the message.raw field. I tried different things.

  1. Suspected that this would work out of the box by just using title.raw and hoping that Elasticsearch would convert it to message.raw. Didn't work.

  2. Specified raw as a field in title:

"title":{
    "type":"alias",
    "path":"message",
    "fields":{
        "raw":{
            "type":"alias",
            "path":"message.raw"
        }
    }
}

This generates the following error when updating the mapping: Mapping definition for [title] has unsupported parameters: [fields : {raw={type=alias, path=message.raw}}]

  1. Specified title.raw as a new field:
"title":{
    "type":"alias",
    "path":"message"
},
"title.raw":{
    "type":"alias",
    "path":"message.raw"
}

This results in an error: Cannot merge a field alias mapping [title] with a mapping that is not for a field alias.

Is this supported somehow?

1

1 Answers

1
votes

Referencing multi-fields from an alias isn't supported. From the documentation: aliases cannot be used as the target of copy_to or in multi-fields.

You can create an alias for your multi-field without the dot. What you need to do is simply to name the title.raw field differently, e.g. title_raw:

"title":{
    "type":"alias",
    "path":"message"
},
"title_raw":{                    <--- change the name here
    "type":"alias",
    "path":"message.raw"
}

Then you can query message.raw the same way as title_raw.