Best practice about reindex

I got
index_A --> hold the data 2022

index_B_Jan --> hold the data of jan 2023
index_B_Feb --> hold the data of Feb 2023
index_B_Mar --> hold the data of Mar 2023
.....
index_B_Dec --> hold the data of Dec 2023

now I would like to combine all index of 2022 and 2023

Method 1

POST _reindex
{
  "source": {
    "index": ["index_B_*"]
  },
  "dest": {
    "index": "index_A "
  }
}

then remove index_B_*

Method 2

POST _reindex
{
  "source": {
    "index": ["index_B_*"]
  },
  "dest": {
    "index": "index_C "
  }
}
POST _reindex
{
  "source": {
    "index": ["index_A", "index_C"]
  },
  "dest": {
    "index": "index_D "
  }
}

Then remove index_A, index_B*, index_C

I would like to know that is the best practice. Which method perferred. Or there is any other better method.

Depending on your use case, you could also think of just using an alias which points to all your indices...

I'll probably do method1 as it avoids reindexing one of the indices.

1 Like

Big thx.

I am actually attempting to minimize the number of shards as well. :wink:

How many shards do you have per index? If more than one, you can also use Shrink index API | Elasticsearch Guide [8.13] | Elastic