Loading...

Move documents to another Index in Elasticsearch

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

If you run into the situation, that documents were written to a wrong index, you can use the Reindex API to copy the documents to the desired index. You can remove them afterwards with the Delete By Query API.

First of all a simple search query.

GET prod/_search
{
  "query": {
    "match": {
      "application": "ep-deux"
    }
  }
}

Copy only queried data

POST _reindex
{
  "source": {
    "index": "fo-prod-2017.05.01",
    "type": "json",
    "query": {
      "match": {
        "application": "ep-deux"
      }
    }
  },
  "dest": {
    "index": "fix-2017.05.01"
  }
}

Check with the Task API the status of the reindex action.

GET _tasks?detailed=true&actions=*reindex

Delete old documents

POST fo-prod-2017.05.01/json/_delete_by_query?conflicts=proceed
{
  "query": {
    "match": {
      "application": "ep-deux"
    }
  }
}
Please remember the terms for blog comments.