Does creating a Field Alias requires reindexing?

Typically modifying the index mapping requires reindexing existing data. I'm look at reference in the documentation whether creating Field Alias does or does not require reindexing. Is it confirmed that if I modify the index mapping with new field aliases, I'll be able to subsequently use search API with the new field aliases to refer to existing fields?

Thanks

Hi @HotPocket Welcome to the community.

No adding an alias does not require re-indexing

See this example

PUT discuss-test
{
  "mappings": {
    "properties": {
      "foo" : {"type": "keyword"}
    }
  }
}

POST discuss-test/_doc
{
  "foo" : "bar"
}

POST discuss-test/_doc
{
  "foo" : "bah"
}

POST discuss-test/_doc
{
  "foo" : "baz"
}


POST discuss-test/_mapping
{
  "properties": {
    "new-foo": {
      "type": "alias",
      "path": "foo"
    }
  }
}

GET discuss-test/_search
{
  "fields": ["*"], 
  "query": {
    "term": {
      "new-foo": {
        "value": "bar"
      }
    }
  }
}

#Results


# GET discuss-test/_search 200 OK
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 0.9808291,
    "hits": [
      {
        "_index": "discuss-test",
        "_id": "H-24jowBVM3tgE6xNJBp",
        "_score": 0.9808291,
        "_source": {
          "foo": "bar"
        },
        "fields": {
          "new-foo": [
            "bar"
          ],
          "foo": [
            "bar"
          ]
        }
      }
    ]
  }
}

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