Elasticsearch reindex then cant add mapping

Hi Elasticsearch experts! Wondering if someone can help with a strange thing that is happening: We have an index in which the amount of mappings has grown massive (over 3000) and we want to reduce this by reindexing. In the new index we will have dynamic mappings turned off and only add the mappings which we will want to use to search. So, I created an new index:

PUT /newindex-2021.01/_mapping
{
  "dynamic": "false",
  "date_detection": true,
  "properties": {
    "timestamp": {
      "type": "date"
    }
  }
}

Then I reindexed:

POST _reindex?wait_for_completion=false
{
  "source": {
    "index": "oldindex-2021.01"
  },
  "dest": {
    "index": "newindex-2021.01"
  }
}

Then I wanted to add an mapping for the event field to test that everything is working so I ran:

PUT /*newindex*/_mapping
{
  "properties": {
    "event": {
      "type": "text"
    }
  }
}

and to be safe, i also ran (not sure if this had any effect):

PUT /newindex-2021.0/_mapping
{
  "properties": {
    "event": {
      "type": "text"
    }
  }
}

When I navigate to the discover page, it now shows the magnifying glass for the event field (signalling that I can search for just event as a mapping had been created). However, when i click it, no results show (as if there are no documents which have the field event == the value despite it definitely existing) Is there something that I am missing? I simply want to add a mapping to an empty index.. Thanks for your help!

Important note: Adding a new field via the put mapping API does NOT change your data. So in order to index that field, you need to reindex (or run an update by query on that index in order to reindex all documents within that index).

I suppose that this is the issue here, but so far this is just an educated guess :slight_smile:

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