Troubleshooting Connection Issues for Elasticsearch

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

Bitbucket Server is unable to connect to Elasticsearch.

One of the following log line appears in the atlassian-bitbucket.log:

  1. Connection refused

    1 2 DEBUG "POST /rest/search/latest/search HTTP/1.1" c.a.b.s.internal.rest.SearchResource Connection exception: Connection refused: no further information DEBUG "POST /rest/search/latest/search HTTP/1.1" c.atlassian.bitbucket.search.timing Timing: Search request execution took 1.023 s [1022 ms] for query 'XXX'
  2. HTTP 401 status code

    1 DefaultElasticsearchConnectionTester Testing connection with Elasticsearch failed: HTTP response status code is 401

This will cause a large error on the screen when performing a search.

Diagnosis

  • There are no details in the Elasticsearch username and/or password fields

  • The option to let the installer startup Bitbucket Server was not chosen

If you are receiving 401 errors, these indicate that authentication issues are happening - meaning it's important to check if Bitbucket has been configured with the correct credentials to access Elasticsearch.

Once the application has started up, it's suggested that you fully execute a test of Elasticsearch at Administration (cog in the top right) → Server Settings → Test Elasticsearch Connection

If you receive the error "Access to Elasticsearch was denied. Check your settings.", then it's highly recommended you follow the steps listed in "Access Denied" when testing connection to search server in Bitbucket Data Center in order to help confirm that the credentials you're using are correct.

Cause

This depends on what error you were seeing in the logs:

Stacktrace #1 - Connection Refused

Elasticsearch was not started.

Stacktrace #2 - HTTP 401 Errors

This is due to the fact that Bitbucket Server started before Elasticsearch on the first-ever run. Therefore Bitbucket Server did not get to negotiate a username and password for Elasticsearch. This negotiation only happens during the Bitbucket Server startup. Therefore if it is missed, it doesn't get the chance to try again. This really only has to succeed once.

Solution

The resolution is the same for both cases and requires the following steps to be performed:

  1. Start Elasticsearch

  2. Restart Bitbucket Server

The steps on how to perform the restart are detailed on the Start and stop Bitbucket page.

This will then mean that Elasticsearch is already waiting for Bitbucket Server to start up. Therefore when Bitbucket Server gets to the stage of startup where it attempts to negotiate a password, Elasticsearch will be ready to accept that connection.

  • If you are using Remote Elasticsearch, Start the Elasticsearch services first and then the Bitbucket application Services.

  • If you are using Bundled Elasticsearch, Restart the Bitbucket Application Services. Bundled Elasticsearch will be automatically started when the Bitbucket application service starts.

Bitbucket Server 5.0

As of Bitbucket Server 5.0 release notes, Bundled ElasticSearch is now automatically started when the Bitbucket application is started.

Windows

With a Windows service:

  • Restart ElasticSearch Service

  • Restart Bitbucket service

Without a Windows service:

In both cases you can solve your issues by following these steps:

1 2 3 > cd <Bitbucket Server installation directory> > bin\stop-bitbucket.bat > bin\start-bitbucket.bat

Linux

With a Linux service:

In both cases you can solve your issues by following these steps:

# service atlbitbucket stop # service atlbitbucket start

Without a Linux service:

> cd <Bitbucket Server installation directory> > bin/stop-bitbucket.sh > bin/start-bitbucket.sh

Updated on April 11, 2025

Still need help?

The Atlassian Community is here for you.