1

I had @Document(shards=5) for my entity in my SpringBoot application using Spring Data Elasticsearch. I have realised it is too resource consuming and have reduced it to @Document(shards=1) and just redeployed the java app with new code. I did no action on ElasticSearch side.

Should the Jest client do all the best to reduce the number of shard used, or it should be done by myself being Elasticsearch admin?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Eljah
  • 4,188
  • 4
  • 41
  • 85

2 Answers2

1

Spring Data Elasticsearch uses this information when creating the index; it it not reapplied to change parameters like the numner of shards. So what you want to do is not possible with Spring Data Elasticsearch.

If you can afford to drop the data and have a possibility to reload it, then delete the index, restart your program with the changed @Document annotation and reload the data.

If you cannot simply reload the data, you can do the following directly in Elasticsearch (for the exact commands please refer to the Elasticsearch docs):

  • create a new index with the shard settings you want to have and name it for example index-new
  • reindex your old index to the new index
  • if you can live with the new index name, change your @Document annotation to use the new index.
  • if not, drop the old index and create it anew with the old name and the new settings, and the reindex from index-new to the index with the new name
P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
0

Once an index is created with a given number of primary shards, you can't modify it. Simply redeploying your app probably won't recreate the index and you'll need to delete it first and let your app recreate it with the new number of shards on start-up.

You can easily see if the change was applied or not (i.e. whether your index has 5 or 1 shard) using:

GET _cat/shards/your-index-name
Val
  • 207,596
  • 13
  • 358
  • 360