How to change number of shards for Elastic search in Bitbucket server?
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
From Elastic search version 7 (we are on 7.5.x), the default value for the number of primary shards per index is 1. In earlier versions, the default was 5 shards.
Environment
Bitbucket Server and Datacenter
Elastic search 7.5.2
Solution
Bitbucket uses index templates when creating the indices and configures the number of shards to 5. The shard configuration can be changed with a system property applied through an environmental variable JVM_SUPPORT_RECOMMENDED_ARGS=-Dindex.codesearch.node.shards.num=1
(for example, to change the shards from 5 to 1)
Shut down Bitbucket
In the start-webapp.sh file located at $BITBUCKET_INSTALLATION_DIR/bin, there is a line that says JVM_SUPPORT_RECOMMENDED_ARGS=
Uncomment out the line and add:
-Dindex.codesearch.node.shards.num=1
JVM_SUPPORT_RECOMMENDED_ARGS=-Dindex.codesearch.node.shards.num=1
Restart Bitbucket
Perform a full re-index of the Elasticsearch index
⚠️ Please ensure you perform a full re-index if Elasticsearch index or the indices might get corrupted.
Was this helpful?