Search code examples
elasticsearchkibanaelasticsearch-7kibana-7

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!


Solution

  • You cannot change the mapping of documents that have been already indexed (in fact, this is exactly why you're correctly reindexing your original index). What you did after reindex was to add a new mapping to a field that didn't have any, making it queryable from now on - i.e., only for new documents, not retroactively to the existing ones.

    You will need to reindex to an index with a mapping that already includes the field mapping you're looking for.