Does sending all properties in PUT mappings require reindexing?

Hey yall, had a question on PUT mapping.

From the doc above, I understand we can add new fields to the current mapping by just providing the fieldname and the properties of that field.

However I’m wondering, is it possible, or is opensearch smart enough under the hood to take in the current mappings with new fields added. I can see from the console that the new fields are added, but does the existing fields get touched in this process or do they get skipped?

I can see from the errors that it does complain when an existing field is being modified. But I’m wondering if existing fields are getting updated with this command and would they need reindexing.

Hey @gsitu322 ,

I do not entirely understand your question but will try to share how things work in general. So yes, you could add a new property to the existing index mapping. For newly ingested documents the property is going to be populated but the existing documents have to be backfilled manually. For existing mapping properties, you could only do very limited set of modifications - the ones that do not require reindexing, otherwise the modification will be rejected. For the same reasons, you cannot remove fields from the existing mappings. Also, when you add new field to the mappings, the existing fields are not affected anyhow. Hope it helps.

Yea, l could clarify with some code. Lets say I have this as my mapping

{
    "mappings": {
        "properties": {
            "first_name": { "type": "keyword" },
            "last_name":  { "type": "keyword" },
            "email":      { "type": "keyword" },
            "books": { 
                 "type": "nested",
                 "properties": {
                      "name":         { "type": "keyword" },
                      "is_favorite":  { "type": "boolean" }
                  }
             }
    } 
}

If I want to add the phone and num_times_read fields to my mapping can I just resend the the existing fields with the new fields included?

PUT /myIndex/_mapping
{
    "properties": {
        "first_name":    { "type": "keyword" },
        "last_name":     { "type": "keyword" },
        "email":         { "type": "keyword" },
        "phone":         { "type": "integer" },
        "books": { 
             "type": "nested",
             "properties": {
                  "name":           { "type": "keyword" },
                  "is_favorite":    { "type": "boolean" },
                  "num_times_read": { "type": "integer" }
              }
         }
}

When I check the mapping on openseach, I see the new fields added which is what I want. But would first_name, last_name, is_favorite just ignored from the PUT mapping because they already exist?

@reta Hey leme know if the above code snippets give more clarity

@gsitu322 Oh I see, yes, you should be able to resend the the existing fields with the new fields included, assuming there no breaking changes to existing fields in the mapping (in other words, if existing fields stay unchanged - not an issue).

@reta

Awesome! thanks for the insight!