Skip to content

Upgrading mappings which uses index_name and path #11079

@clintongormley

Description

@clintongormley

In 2.0, I think we can upgrade the mapping in a way that is not perfect, but will cover most use cases and help users to upgrade without reindexing.

index_name and path are used for two main purposes:

  • the old way to do copy_to
  • provide fieldname aliases, eg tag points to tags

We can't distinguish between these two use cases automatically, but we can handle the first use case gracefully, and the second use case is an easy change to make application side (ie just change all use of tags to tag in searches)

A mapping that looks like this (with path set to just_name):

{
  "mappings": {
    "test": {
      "properties": {
        "name": {
          "type": "object",
          "path": "just_name", 
          "properties": {
            "first": {
              "type": "string",
              "index_name": "fullname"
            },
            "last": {
              "type": "string",
              "index_name": "fullname"
            }
          }
        }
      }
    }
  }
}

could be rewritten to:

{
  "mappings": {
    "test": {
      "properties": {
        "fullname": {
          "type": "string"
        },
        "name": {
          "type": "object",
          "properties": {
            "first": {
              "index": "no",
              "copy_to": "fullname"
            },
            "last": {
              "index": "no",
              "copy_to": "fullname"
            }
          }
        }
      }
    }
  }
}

The mapping for the new fullname field can just be the same as the mapping of the first field which uses index_name (without the index_name) setting. The original field will not be indexed (or searchable).

In the case where path is set to full, the same rules apply, but the new field uses the full path name, ie this:

{
  "mappings": {
    "test": {
      "properties": {
        "name": {
          "type": "object",
          "path": "full", 
          "properties": {
            "first": {
              "type": "string",
              "index_name": "fullname"
            },
            "last": {
              "type": "string",
              "index_name": "fullname"
            }
          }
        }
      }
    }
  }
}

could be rewritten as:

{
  "mappings": {
    "test": {
      "properties": {
        "name": {
          "type": "object",
          "properties": {
            "first": {
              "index": "no",
              "copy_to": "name.fullname"
            },
            "last": {
              "index": "no",
              "copy_to": "name.fullname"
            },
            "fullname": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions